I'm trying to create a database within ny server using php script. I have a script that I have found in a book that I copied to use,However I must have copied it wrong or it has a bug i can't figure out, Need Help. Thanks.
<?php

$conn = @mysql_connect("localhost","frank","")
or die( "Sorry - could not connect to MySQL");

$rs1 = @mysql_create_db( $_REQUEST['db'] );

$rs2 = @mysql_list_dbs( $conn );

for( $row = 0; $row < mysql_num_rows( $rs2 ); $row++ )
{ $list .= mysql_tablename( $rs2, $row) . " | "; }
?>
<html><head><title>Creating databases</title></head>
<body>
<form action = "<?php echo( $_SERVER['PHP_SELF'] ); ?>"
method="post">Current databases: <?php echo( $list ); ?>
<hr>Name:<input type = "text" name = "db">
<input type = "submit" value = "Create database">
</form></body></html>

    It doesn't display on my server, I have it in my /var/www/html directory with the rest of my files that work well. Will not display?

      What won't display? Look you have to ask sensible questions to get sensible answers.

        The server web page as a form. The very thing that it suposed to do.

          Since you're having problems with the script, why are you suppressing the error messages? Remove all of the '@' signs, and verify that display_errors is set to On and error_reporting is set to E_ALL. A more descriptive explanation of what is happening/not happening, as Roger points out, would be quite helpful.

            When I call ithe http://localhost/create_db.php I dont get an error message just a blank white screen?
            This scipt is supposed to have a form which will have current databases and have a place to create a new database.

            PS I'm totally new, Thanks

              Hi,

              Sorry, but -unless your server is completely mal-installed- there is no way this is creating a fully blank page, especially when you remove all the @ symbols.

              Please post -between [php ] [/php ] tags- the EXACT script as you run it, and exactlu the output it creates.

              J.

                <?php
                
                $conn = mysql_connect("localhost","frank","")
                               or die( "Sorry - could not connect to MySQL");
                
                $rs1 = mysql_create_db( $_REQUEST['db'] );
                
                $rs2 = mysql_list_dbs( $conn );
                
                for( $row = 0; $row < mysql_num_rows( $rs2 ); $row++ )
                { $list  .= mysql_tablename( $rs2, $row) . " | "; }
                ?>
                <html><head><title>Creating databases</title></head>
                <body>
                <form action = "<?php echo( $_SERVER['PHP_SELF'] ); ?>"
                method="post">Current databases: <?php echo( $list ); ?>
                <hr>Name:<input type = "text" name = "db">
                <input type = "submit" value = "Create database">
                </form></body></html>
                
                
                

                  What was wrong with php code? I Can't learn if I can't get an answer I understand.
                  Nothing is wrong with my server, I do get other php codes to work well, I'm just curious to find out what mistakes are in this code? I would really like to find out.

                    So, give the information being asked for by the people trying to help you.

                    That script must output at least the text in the html content unless it terminates with a php error before the html is reached, in which case you should be getting a php error message.

                      As I said.. What is the output of the script please.

                      I do not see any clear reason why the script would not produce output.

                      But..

                      1) $_REQUEST['db'] will not produce anything when you do not post / URL-load any variables.

                      2) $rs1 = mysql_create_db( $_REQUEST['db'] ); will therefor nore work on first load

                      3) $rs2 = mysql_list_dbs( $conn ); if there are not tables, this will not result in output

                      4) for( $row = 0; $row < mysql_num_rows( $rs2 ); $row++ )
                      use: while($row = mysql_fetch_array($rs2)) instead

                      The form code looks ok, and should produce output.
                      { $list .= mysql_tablename( $rs2, $row) . " | "; }
                      ?>

                        Hello, First let me say thanks for the replies.
                        Now I just started to explore php for the first time, I picked up this book "PHP5 in easy steps" by Mike McGrath from Barnes & Noble easy learn series.
                        I'm running Linux Fedora core 6, I have installed and running Apache2.2 server, MySQL5.0.27 and PHP5.1.6. I've been doing lessons from this book and have gotten php to work simple code on my server.
                        This is what the code should:
                        "The example below displays all existing databases, then provides a form where a new database name can be input. When the form submitted,the script attempts to create a new database with the specified name."

                        When it is run I just recieve a blank white space below the URL bar

                          Typical shoddy book code, exactly NOT how to write PHP.

                          OK: view source to see what is behind the blank page. - paste whatever you see here.

                            Nothing behind source page? Blank also, May I ask you? I've been writing php source code in the
                            gedit editor which comes with Feddora 6, I like it but I really don't know if I use it well enough to tell if any lines are buggy, Can you recommend an editor for linux that can debug my source code if I write it wrong or if I leave something out?
                            Thanks

                              This problem is not in your code. Your code would at least create the form. There is a thread on editors on the forums somewhere. do a search

                                Thanks leatherneck, found an editor called eclipse for fedora, I'll try it out.
                                thanks once more. fvs

                                  Do any php scripts work on your server? Have you told Apache what to do with php files? Cos that's the only reason I can think of for totally blank output. Simple test, take out all the php code and leavr just the html but keep the .php extension, you should then see the form, if you don't then it is apache config.