Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: MySQL error

  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    MySQL error

    Hey guys, MySQL has been giving me this error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 13

    I honestly can't figure out what the problem is. The code is:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Registration Complete</title>
    </head>
    <body>
    <?php
    include('cn.php');

    $userUsername $_POST['userUsername'];
    $userPassword $_POST['userPassword'];
    $userPasswordConfirm $_POST['userPasswordConfirm'];
    $userEmail $_POST['userEmail'];
    $userEmailConfirm $_POST['userEmailConfirm'];
    $userMinutes 0;
    $userHours 0;


    //Prevent MySQL Injections
    $userUsername mysql_real_escape_string(stripslashes($userUsername));
    $userPassword mysql_real_escape_string(stripslashes($userPassword));
    $userPasswordConfirm mysql_real_escape_string(stripslashes($userPasswordConfirm));
    $userEmail mysql_real_escape_string(stripslashes($userEmail));
    $userEmailConfirm mysql_real_escape_string(stripslashes($userEmailConfirm));

    //Retrieve every existing user
    $sql "SELECT * FROM user";
    $resultCount mysql_query($sql$cn) or
        die(
    mysql_error($cn));

    //Check how many users were returned
    $num_users mysql_num_rows($resultCount);

    //Check individually in each row if the selected row is already in use
    $row_count = -1;
    while(
    $row_count $num_users) {
        
    $data mysql_fetch_object($resultCount);
        
    $row_count++;
        
        
    //If username is already in existence
        
    if ($data->user_username == $userUsername) {
            echo 
    '<p>The username "' $userUsername '" is not available.</p>';
            
    $row_count $num_users;
        } else if (
    $row_count == $num_users) {
            if (
    $userPassword != $userPasswordConfirm) {
                echo 
    '<p>Passwords do not match. Please try again.</p>';
                echo 
    '<p>User has not been created.</p>';
            } else if (
    $userEmail != $userEmailConfirm) {
                echo 
    '<p>Emails do not match. Please try again.</p>';
                echo 
    '<p>User has not been created.</p>';
            } else {
                
                
    $sql "INSERT INTO
                        user
                    (user_username,
                     user_password,
                     user_email,
                     user_minutes,
                     user_hours)
                        VALUES
                    ('" 
    $userUsername "',
                     '" 
    $userPassword "',
                     '" 
    $userEmail "',
                     '" 
    $userMinutes ."',
                     '" 
    $userHours ."',)";
                    
    $result mysql_query($sql$cn) or 
                        die(
    mysql_error($cn));
                        
                    echo 
    "<p><strong>The username '" $userUsername "' has been created! Please login (a href='login.php'>here</a>.</strong></p";
            }
        }
    }


    ?>
    If someone could take a look and maybe figure out my problem, that'd be great. Thanks!
    Last edited by dstars5; 08-21-2012 at 09:30 PM. Reason: Resolved

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    DEBUG DEBUG DEBUG.
    Code:
                $sql = "INSERT INTO
                        user
                    (user_username,
                     user_password,
                     user_email,
                     user_minutes,
                     user_hours)
                        VALUES
                    ('" . $userUsername . "',
                     '" . $userPassword . "',
                     '" . $userEmail . "',
                     '" . $userMinutes ."',
                     '" . $userHours ."',)";
    
    echo "<hr/>DEBUG SQL: " . $sql . "<hr/>\n";
    
                    $result = mysql_query($sql, $cn) or 
                        die(mysql_error($cn));
    If you can't figure it out after looking at the debug output, then copy/paste the debug output here.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    I do see one very very obvious problem:
    Code:
                     '" . $userHours ."',)";
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    dstars5 (08-21-2012)


  •  

    Tags for this Thread

    Posting Permissions

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