Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    I'm certain that my problem is something really silly, but members of the forum seem particularly patient with newbies like me, so I thought I'd ask here for help.

    I have Apache/MySQL/PHP installed (and working) on my computer. I am trying to create a form with a text box and submit buttonI can use to create a database. The script I am using comes directly from the book I am using. When I open it in Explorer, I get a blank page.

    Here is the markup I am using:

    <?php
    $conn = @mysql_connect( "localhost", "dave", "bingo" )
    or die( "Sorry - could not connect to MySQL" );
    $rs1 = @mysql_create_db($_REQUEST['db']);
    $rs2= @mysql_list_dbs($conn);
    $list = "";
    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>
    *************

    If I remove the entire $rs1 line, I am able to see the current database list and form (but of course it doesn't work).

    I have no idea what is wrong. Any advice would be greatly appreciated. Thank You.

  2.  

  3. #2
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Has Dave definitely got the privilege to create databases?

    Have you tried connecting to your database manually and then seeing what happens when you type the create database command at the mysql> prompt ?

    Sean

  4. #3
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    Yes, I have granted all privileges,using the command: grant all privileges on *.* to mike@localhost identified by "bingo" with grant option;--(replacing "mike" and "bingo" with my user name and password, of course; if I actually use "mike" and/or "bingo" I get the message that I cannot connect). I am able to add/change/remove databases through my My SQL (and also through My SQL Administator. I have similar scripts from the book I am using to learn that allow me to create/add tables and entries that work fine. There are only two that I can't seem to get to work--create database and delete database. I also know that I am connecting to MySQL because when I remove the $rs1 line, I can see the list of databases in the explorer window, along with the text box and button. When I add the $rs1 line, the window goes blank.

    Sorry if I am repeating myself, or going on too long, I just want to be sure I provide as much information as possible in hopes of getting help figuring out what I am doing wrong.

    Thank you for responding, and I hope you (or another member) can get me through this step.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    As you noted, this code:
    Code:
    $rs1 = @mysql_create_db($_REQUEST['db']);
    is your problem. The reason is that you're using what looks like an unset variable -- $_REQUEST['db']. What the code ends up looking like, once PHP has parsed it, is:
    Code:
    $rs1 = @mysql_create_db( '' );
    Which results in what is most likely a MySQL error concerning the blank database name.

    Note that, to get more error output, you can remove the @s from in front of the function calls. These suppress errors which I generally find to be at least somewhat useful.

    Anyway, the best way to fix this if this is indeed the problem would most likely be replacing the above with:
    Code:
    if ( isset($_REQUEST['db']) && $_REQUEST['db'] != '' )
        $rs1 = @mysql_create_db( $_REQUEST['db'] );

  6. #5
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    Thank you for the suggestion! Unfortunately, I am still having problems.

    I am hoping that I understood your post correctly. What I did first was remove all three @ before the function calls. I saved and opened up the page, which still came up blank.

    I then replaced:
    $rs1 = @mysql_create_db($_REQUEST['db']);
    with:
    if ( isset($_REQUEST['db']) && $_REQUEST['db'] != '' )
    $rs1 = @mysql_create_db( $_REQUEST['db'] );

    Which did get me little further---I was able to see my databases listed, as well as the text box and submit button. However, when I entered a name and clicked on create database, the window once again reverted to a blank screen. Refreshing still gave me a blank screen. The only way to get back to the list and text box is to open a new Explorer window.

    Also, the new database is not listed, either in MySQL or MySQL Administrator.

    Obviously, I am still doing something wrong! Grr, Argh!!! But I have no idea what! Any further suggestions would be greatly appreciated! Thank you!

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    This is tremendously strange, especially considering the fact that everything works fine on my test server with the right credentials substituted.

    Try this:
    * First of all, at the end of every mysql_* function, add an `or die(mysql_error())'.
    * Second of all, add this to the beginning:
    Code:
    ini_set( 'display_errors', '1' );
    ini_set( 'display_startup_errors', '1' );
    ini_set( 'error_reporting', E_ALL );
    And see what happens.

    Also, note the fact that mysql_create_db has been deprecated in favor of using mysql_query with a "CREATE DATABASE" query, according to a notice I got when I tried running this.

  8. #7
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Why don't you replace $_REQUEST['db'] with a hardcoded value just to make sure that it isn't something to do with the variable?

    ie.
    Code:
    $rs1 = mysql_create_db('xyz_test');
    And, as Shadowfiend suggested, get rid of those "@" signs... you want all the debug/error messages you can get when a script isn't working... suppressing them is just making your life more difficult!

    Sean

    ps. I'd also replace $_REQUEST[] with $_POST[] ...normally accepted as best practice.

  9. #8
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    Thank you both for your suggestions. I realize that I am extremely new at this, and appreciate your patience. I'm trying to add as my detail as possible not just to get this script to work, but also to understand what it is I am doing. I really appreciate your help. As for my script,still no luck on my end.

    Here's where I am at: I had already removed the '@', and added the 'ini set' lines. That allowed me to view the db list, text box and submit button, but when clicked, once again brought me to a blank page without adding the db. I added the 'or die' lines, which then gave me a blank page from the get-go. No error messages at all, just a blank Explorer window.

    I am attaching the file with the current file (I have no idea how to add those nifty textareas into a post).

    Shadowfiend, regarding your comment 'the fact that mysql_create_db has been deprecated in favor of using mysql_query with a "CREATE DATABASE" query', if it makes any difference, the book that I have refers to MySQL version 4.0.18; I have ver 4.11.11. Could this be what is causing my problem? (The initial markup I had (see first post) was taken directly from the book's example). In later lessons, I am able to add tables and entries to existing dbs using the examples given.

    Sean, as for using a hardcoded value, that (might) create the new db, but if I understand what I am doing correctly , that would defeat the purpose of the exercise, which is have a form to create a new db with the specified name.

    By the way, I've gotten so frustrated, I've ordered a new book.

    Thank you again for your time and attention.

  10. #9
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Quote Originally Posted by strans
    Thank you both for your suggestions. I realize that I am extremely new at this, and appreciate your patience. I'm trying to add as my detail as possible not just to get this script to work, but also to understand what it is I am doing. I really appreciate your help. As for my script,still no luck on my end.

    Here's where I am at: I had already removed the '@', and added the 'ini set' lines. That allowed me to view the db list, text box and submit button, but when clicked, once again brought me to a blank page without adding the db. I added the 'or die' lines, which then gave me a blank page from the get-go. No error messages at all, just a blank Explorer window.

    I am attaching the file with the current file (I have no idea how to add those nifty textareas into a post).
    At a glance, it looks like this is for PHP 5. I didn't try it on PHP 5. However, there's a note in the PHP manual:

    Note: This function will not be available if the MySQL extension was built against a MySQL 4.x client library.
    This makes me think that you most likely are experiencing an error where the function does not exist.

    Quote Originally Posted by strans
    Shadowfiend, regarding your comment 'the fact that mysql_create_db has been deprecated in favor of using mysql_query with a "CREATE DATABASE" query', if it makes any difference, the book that I have refers to MySQL version 4.0.18; I have ver 4.11.11. Could this be what is causing my problem? (The initial markup I had (see first post) was taken directly from the book's example). In later lessons, I am able to add tables and entries to existing dbs using the examples given.
    The deprecation happens between versions of PHP, as opposed to versions of MySQL. As you saw above, however, it is possible that PHP disabled that command due to the MySQL version it was built against.

    Quote Originally Posted by strans
    Sean, as for using a hardcoded value, that (might) create the new db, but if I understand what I am doing correctly , that would defeat the purpose of the exercise, which is have a form to create a new db with the specified name.
    It would defeat the purpose; however, the idea was to see if it worked so we could determine if it was the function that was failing or the table names you were giving it.

    Quote Originally Posted by strans
    By the way, I've gotten so frustrated, I've ordered a new book.

    Thank you again for your time and attention.
    Well, while you're waiting, why don't you try replacing your call to mysql_create_db with the following:
    PHP Code:
    $rs1 mysql_query'CREATE DATABASE ' $_REQUEST['db'], $conn ); 
    See if that works :-).

  11. #10
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    Shadowfiend, you are so awesome!

    I replaced the $rs1 line ith '$rs1 = mysql_query( 'CREATE DATABASE ' . $_REQUEST['db'], $conn );' and it worked like a charm!

    Looking throught the PHP manual you refered me to above (thank you), am I correct in that for the next lesson, deleting a database, I should replace the following line:

    $rs1 = mysql_drop_db( $_REQUEST['db'] );
    with:
    $rs1 = mysql_query( ' DROP DATABASE ' . $_REQUEST['db'], $conn );

    BTW, The book I have is indeed for PHP 5, the version I have installed is 5.0.4.

    Thank you again for all of your help and advice, and especially for the great link!


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:21 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com