Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Appending $db->Database to a filename

Posted on 2008-11-11
4
Medium Priority
?
259 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:Simon336697
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
vibrazy earned 2000 total points
ID: 22930449
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22930796
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22930847
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
 
LVL 5

Expert Comment

by:vibrazy
ID: 22931401
Im glad you got it sorted!!

:)

Regards,
Dan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question