Appending $db->Database to a filename

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

LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vibrazyCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author 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?


0
Simon336697Author 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 :>)
0
vibrazyCommented:
Im glad you got it sorted!!

:)

Regards,
Dan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.