472,119 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

MySQL help...Getting errors

Ok, I'm trying to poineer into the wonderful area of PHP/MySQL programming, but I'm having some difficulties. http://www.paulhq.com/php/freepage.html should register, but when anyone fills something out, it returns a MySQL error: Could not insert data because 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 1

Here are the codes:

freepage.html ::
[PHP]<form action="register.php" method="post">
<strong>Username:</strong></td><td><input name="username" /></td></tr>
<br />[3-12 letters/numbers]</strong></td><td><input type="password" name="secure" /></td></tr>
<tr><td><strong>Email: [Valid Please]</strong></td><td><input name="email" /></td></tr>
<tr><td><strong>MSN Email:</strong></td><td><input name="MSN" /></td></tr>
<tr><td><strong>Yahoo:</strong></td><td><input name="yahoo" /></td></tr>
<tr><td><strong>AIM:</strong></td><td><input name="AIM" /></td></tr>
<tr><td><strong>ICQ Number:</strong></td><td><input name="ICQ" /></td></tr>
<tr><td><strong>Picture URL:</strong></td><td><input name="pic" /></td></tr>
<tr><td colspan="2"><div align="center">
<input type="submit" value="Register!"></div></td></tr></table>
I just included the form to save space... That's the only thing that really matters anyways.

register.php ::


// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $username is already taken.<br>";
echo "<a href=register.html>Try again</a>";
} else {

// insert the data
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['secure']."', '".$_POST['email']."', '".$_POST['msn']."', '".$_POST['yahoo']."', '".$_POST['aim']."', '".$_POST['icq']."', '".$_POST['picture']."',)")
or die("Could not insert data because ".mysql_error());

// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=login.html>log in</a>";

This is the script that handles the information given on the registration form.

config.php ::
$server = "localhost"; // server to connect to.
$database = "ptn_php"; // the name of the database.
$db_user = "ptn_****"; // mysql username to access the database with.
$db_pass = "******"; // mysql password to access the database with.
$table = "users"; // the table that this script will set up and use.
I've starred out sensitive information, but it's all correct.

Thanks for any help you can give me!
Mar 11 '06 #1
2 2903
There's bound to be a syntax problem in the "insert the data" command. Lots of ' and " and . can easily create a problem. I'm really tired right now but go over that carefully and see if there's a missing quote or something. If not, there's something it doesn't like about the fields, like maybe try using variables instead of raw POST data.
Mar 12 '06 #2
9,065 Expert Mod 8TB
In your isert statement the very last piece of text is "',)" the comma is superflous and causing the error it should be "')"
Mar 12 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Aaron Harvey | last post: by
reply views Thread by bruce | last post: by
reply views Thread by Mike Chirico | last post: by
4 posts views Thread by James E Koehler | last post: by
6 posts views Thread by MBS | last post: by
reply views Thread by Bill Bevis | last post: by
8 posts views Thread by eholz1 | last post: by
18 posts views Thread by Bruce A. Julseth | last post: by
10 posts views Thread by Caffeneide | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.