Forum Moderators: coopster
I've been trying to run basic PHP and MySQL book examples locally on a Win XP box using Apache and PHP4.2.1.
One such example is supposed to (a) list existing MySQL databases and (b) allow creation of another database by submitting a HTML form:
<?php
$conn=@mysql_connect("localhost","user1","password1")
or die ("Sorry - cannot connect to mysql");
$list="";
$rs1=@mysql_create_db($db);
$rs2=@mysql_list_dbs($conn);
for ($row=0;$row < mysql_num_rows($rs2); $row++)
{$list .= mysql_tablename($rs2,$row)." ¦ "; }
?>
<form action = "<?php echo ($PHP_SELF);?>" method="post" />
Current databases: <?php echo($list);?>
Name:
<input type="text" name="db">
<input type="submit" value="create database">
</form>
I wondered if anyone had anyone had any ideas on how to get database creation through the browser window to work? Thanks.
If anyone's interested, the example is on p156 of "PHP in Easy Steps" by Mike McGrath. According to that, a new database is supposed to be created, and the browser display should show its name in the list of current databases.
If you look at your form there is a form element named db, in the php there is variable called $db, but to make this work with register globals off you will need to change it to $_POST['db'] (this is because the form is being submitted with method="post".