473,320 Members | 2,088 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,320 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>
<tr><td><strong>Password:
<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>
</form>[/PHP]
I just included the form to save space... That's the only thing that really matters anyways.

register.php ::
[PHP]<?php

include("config.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
mysql_select_db($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>";
exit;
} 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>";
}

?>[/PHP]
This is the script that handles the information given on the registration form.

config.php ::
[PHP]<?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.
?>[/PHP]
I've starred out sensitive information, but it's all correct.


Thanks for any help you can give me!
Mar 11 '06 #1
2 2975
webhead
56
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
Banfa
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

5
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...
0
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...
0
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...
4
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...
4
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...
6
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...
0
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: ...
8
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...
18
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;
10
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');...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.