Appending $db->Database to a filename

Simon336697
Simon336697 used Ask the Experts™
on
Hi everyone hope you are well.
Guys in my php page, i have the following select box in the code snippet.
Im running the following to backup databases which does work:

$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \"".BACKUPDIR.$_POST['filename']."\" 2>&1";

The above results in a .sql file dump being created of the following naming format:
08Nov2008_21.55.27.sql

I want to change the above so that the resulting file created, includes in its filename, the database name selected from the select box, so for example, it might be:
08Nov2008_21.55.27_simesdb.sql
where 'simesdb' is a database selected from the select box.


What im trying to do however, is to change the above to include the database selected from the select box, which is in the following format;

echo "<select name='databaselist' style='width:30%;'>";
while ($db = mysql_fetch_object($db_list)){
echo "<option value='$db->Database'>'$db->Database'</option>";            
}
 echo "</select>";

I have tried doing the following to the $command line:

$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \"".BACKUPDIR.$_POST['filename'].$db->Database"\" 2>&1";

But this errors with:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING etc..
for the above line.

Any help on this would be greatly appreciated.




$db_list = mysql_list_dbs();
				echo "<select name='databaselist' style='width:30%;'>";
				echo	"<option value=''>Make a Backup selection</option>";				
					while ($db = mysql_fetch_object($db_list)){
 						echo "<option value='$db->Database'>'$db->Database'</option>";						
 					}
			  echo "</select>";

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
It looks like the syntax is wrong.

what is this:
"\" 2>&1";

$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \"".BACKUPDIR.$_POST['filename'].$db->Database"\" 2>&1";
 
try
$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \".BACKUPDIR.$_POST['filename'].$db->Database."\2>&1";

Open in new window

Author

Commented:
Hi vibrazy, mate thanks for your help.

I tried what you suggested and I got:

syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

I then tried the following..

$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \"".BACKUPDIR.$_POST['filename'].$db->Database."\" 2>&1";

This did not error, but only gave me what I had originally.....so the $db->Database bit has been ignored.

Im wondering if it is because the 4db->Database is only echoing during the while loop as follows:

$db_list = mysql_list_dbs();
echo "<select name='databaselist' style='width:30%;'>";
while ($db = mysql_fetch_object($db_list)){
 echo "<option value='$db->Database'>'$db->Database'</option>";      
 }

so may not be available OUTSIDE the while loop?

The $command statement is defined only after a POST has been done, which includes what value from the select box has been selected.
So i have to somehow grab what has been selected from the select box.

When the form is posted, I am grabbing the selection with:
$_POST['databaselist'] = escapeshellarg($_POST['databaselist']);

but I dont think by doing the following:

$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \"".BACKUPDIR.$_POST['filename'].$_POST['databaselist'] ."\" 2>&1";

that this will get the user's selection....or would it?


Author

Commented:
The following works mate :>)

$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -R "." -r \"".BACKUPDIR.$_POST['databaselist'].'_'.$_POST['filename']."\" 2>&1";

Thanks so much for your help :>)

Commented:
Im glad you got it sorted!!

:)

Regards,
Dan

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial