Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-21-2012, 07:59 PM   PM User | #1
dstars5
New Coder

 
Join Date: Aug 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
dstars5 is an unknown quantity at this point
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
dstars5 is offline   Reply With Quote
Old 08-21-2012, 08:03 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 08-21-2012, 08:04 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
dstars5 (08-21-2012)
Reply

Bookmarks

Tags
dont know, error, line 13, mysql

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:46 AM.


Advertisement
Log in to turn off these ads.