Author Topic: [SOLVED] New select and mysql error  (Read 180 times)

0 Members and 1 Guest are viewing this topic.

Offline pcwTopic starter

  • Enthusiast
  • Posts: 283
    • View Profile
[SOLVED] New select and mysql error
« on: March 20, 2009, 11:12:53 AM »
Hi, I have written this script to select a database to backup

Code: [Select]
<?php

include("data/required.php");

if (!
mysql_connect($dbhost$dbuser$dbpass)) {
    echo 
'Could not connect to mysql';
    exit;
}

$showtablequery "
SHOW TABLES
FROM
$db
"
;
 
$showtablequery_result mysql_query($showtablequery);
while(
$showtablerow mysql_fetch_array($showtablequery_result))
{
$table $showtablerow[0]."<br />";


print 
"<form action='sqlexport.php?cmd=sqlbackup' method='POST'>";
print 
"<select name='backupFile'>";
print 
"<option>Backup Database</option>";

print 
sprintf("<option value='$table/%s'>%s</option>"$table$table);

print 
"</select>";
print 
"<input type='submit' name='tmpupdate' value='update'>";
print 
"</form>";
print 
"</center>";

print 
'
</td>
        </tr>
      </table>'
;
      }

?>

However it prints a select menu for each table. I want to be able to select the table from one select menu. What do I need to change?

Thanks

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: New select and mysql error
« Reply #1 on: March 20, 2009, 11:18:25 AM »
Only

print sprintf("<option value='$table/%s'>%s</option>"$table$table);

should be in 'while' loop. The rest should be outside.
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline pcwTopic starter

  • Enthusiast
  • Posts: 283
    • View Profile
Re: New select and mysql error
« Reply #2 on: March 20, 2009, 11:26:23 AM »
Thankyou :)