SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Very strange MySQL behavior, any ideas?

    I'm trying to accomplish a simple database operation with MySQL and it doesn't work. Is this really a database that's ready for use??

    It's a form for users to register on the website. This page is a frame within a frameset, hence the JavaScript that sets the parent-frameset variables. Using MySQL database table TBL_PERSON_LOGIN, it's supposed to check to see if that username is already used, and if so alert the user - otherwise insert a new record.

    Essentially, it does "SELECT COUNT(*) FROM TBL_PERSON_LOGIN WHERE USERNAME='myusername'"

    and then, if COUNT(*) is zero, it does

    "INSERT INTO TBL_PERSON_LOGIN (USERNAME,PASSWORD,REGISTERED) VALUES ('myusername','mypassword',NOW())


    The Problem is: The INSERT always gets executed before the SELECT! The net result is that it always says that username (no matter what value it is) is already registered. The INSERT has already happened!

    That's not the way the code is written!! I can do these SQL commands at a mysql command-line and they do work. There are no error-messages.
    Any ideas why this is happening?

    Here is the complete page code (slightly edited)...
    PHP Code:
    <?PHP
    session_start
    ();
    ?>
    <html>
    <head>
    <title>Processing User Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?PHP
    $UserName 
    $_GET["UN"];
    session_register("UserName");
    $Password $_GET["P"];
    session_register("Password");

    $db mysql_connect("""designforge_co_1""");
    mysql_select_db("designforge_com_1",$db) or die("Could not select db!");

    // See if this username is already used...
    $dbResult mysql_query("select COUNT(*) from TBL_PERSON_LOGIN where USERNAME='$UserName'",$db) or die("Query1 failed!");
    $row mysql_fetch_assoc($dbResult);
    echo 
    "COUNT=" $row["COUNT(*)"];
    $n $row["COUNT(*)"];
    if (
    $n 0) {
      echo 
    "<p style=\"color: red\">That UserName ($UserName) is already used.</p>\n";
      echo 
    "<script language=\"javascript\">\n";
      echo 
    "parent.mainFrame.form1.username.focus();\n";
      echo 
    "parent.mainFrame.form1.username.select();\n";
      echo 
    "</script>\n";
      
    mysql_close($db);
      exit();
    } else {
      
    // If that username is not already taken, make a new entry in the TBL_PERSON_LOGIN table....
      
    $dbResult mysql_query("insert into TBL_PERSON_LOGIN (USERNAME,PASSWORD,REGISTERED) values ('$UserName','$Password',NOW())",$db)
         or die(
    "insertion failed.");
    }
    mysql_close($db);
    ?>
    <p>Thank you</p>
    <p><a href="javascript:parent.location='index.html'"><img src="continue.gif"></a></p>
    </body>
    </html>


    Here is the MySQL table definition...

    Field: Type: Null: Key: Default: Extra:
    ID int(11) PRI NULL auto_increment
    USERNAME char(16) UNI
    PASSWORD char(16) YES NULL
    REGISTERED datetime YES

    I've been poke'n and sniffing at this this all week and it's driving me nuts. I'm about to go back to using ASP or something.
    Your help is immensely appreciated!
    James Hurst, jhurst@DesignForge.com
    DesignForge - creators of RobotMind and InteMirror.

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you recognize that this is in fact a mySQL problem disregard the following paragraph.

    I think this is a php problem and if I'm right, posts should probably be made on this thread (a duplicate) to avoid any furthur duplication:
    http://www.sitepointforums.com/showt...threadid=80685
    Last edited by samsm; Oct 20, 2002 at 21:23.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •