Forum Moderators: coopster

Message Too Old, No Replies

creating a mysql database locally

creating a mysql database locally

         

moonbather

12:58 am on Aug 27, 2003 (gmt 0)

10+ Year Member



Hello,

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>

However, (b) does not work. I get this message when the form is submitted to create a new database:

You don't have permission to access /<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>C:\Program Files\Apache Group\Apache\htdocs\create_db.php</b> on line <b>16</b><br /> on this server.

I wondered if anyone had anyone had any ideas on how to get database creation through the browser window to work? Thanks.

Robber

8:17 am on Aug 27, 2003 (gmt 0)

10+ Year Member



I think you may have a setting called register globals turned off, therefore the $PHP_SELF variable is not getting recognised.

Try changing it to $_SERVER['PHP_SELF']

moonbather

10:52 am on Aug 27, 2003 (gmt 0)

10+ Year Member



Thanks Robber, that's moved me forward. I put that in and I'm not getting the error message anymore. But when I submit a new database, all that happens is the input box is cleared.

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.

Robber

11:25 am on Aug 27, 2003 (gmt 0)

10+ Year Member



Ok, well there is another variable that isn't being set due to register globals.

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".

moonbather

4:19 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



Excellent work, Robber. It's now working fine.

The information you provided will be useful in implementing other examples in the book (inserting table data, etc).

Thanks again.

wkitty42

5:12 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



you should note that the additions are needed /because/ the php register globals setting now defaults to OFF for security reasons... with it on, it was too easy for folk to access information about your installation that could lead to them being able to gain access and "root" or "own" the box...

moonbather

1:40 am on Aug 31, 2003 (gmt 0)

10+ Year Member



wkitty42, thanks for the information. I probably won't be touching any settings for the moment.