473,241 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 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 2971
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

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

Similar topics

by: Aaron Harvey | last post by:
I don't know if anyone knows anything about programming C++ to do mysql database manipulation, but here it goes anyway ... I'm getting desperate to find a solution. I'm going absolutely freakin...
by: bruce | last post by:
Hi... Update.... We have the following setup in our httpd.conf file. We've tried to give what's related to the issue. We're trying to set up a virtual host for a test project. The behavior...
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
by: Chefry | last post by:
I'm trying to set up an off the shelf script and keep getting an error. My host set up the mysql on my site and I changed the variables I had to in the settings.php file but I keep getting the...
by: MBS | last post by:
Yeah, read the previous posts...I did that. None answer my question. I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago on WinXP SP2. My goal is to learn to use these...
by: Bill Bevis | last post by:
I'm trying to set up PHP 5.1.3 to run under Apache2, and talk to a MySQL 5.0.21 database, and have been banging my head against a tough install for days. I'm getting a slough of errors like this: ...
by: eholz1 | last post by:
Hello Newsgroup, I have redhat 3.0 Enterprise, and mysql (3.58.xxx more or less) installed from a redhat rpm, and php 4.3.9 (installed from an rpm) - I can access data from my mysql db using php...
by: Bruce A. Julseth | last post by:
I have the following code $Host = "localhost"; $User = "Fred"; $Database = "house"; $Password = "mypw" echo "before mysqli<br />Host: " . $Host . "<br />" . $User . "<br />" . $Database;
by: Caffeneide | last post by:
I'm using a php script which performs three xml queries to other three servers to retrieve a set of ids and after I do a query to mysql of the kind SELECT * FROM table WHERE id IN ('set of ids');...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.