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!