SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    0 Post(s)
    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


    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:
    <title>Processing User Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    $Password $_GET["P"];

    $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);
    "COUNT=" $row["COUNT(*)"];
    $n $row["COUNT(*)"];
    if (
    $n 0) {
    "<p style=\"color: red\">That UserName ($UserName) is already used.</p>\n";
    "<script language=\"javascript\">\n";
    } 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.");
    <p>Thank you</p>
    <p><a href="javascript:parent.location='index.html'"><img src="continue.gif"></a></p>

    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,
    DesignForge - creators of RobotMind and InteMirror.

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Atlanta, GA, USA
    0 Post(s)
    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:
    Last edited by samsm; Oct 20, 2002 at 22:23.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


Posting Permissions

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