Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

help, script error!

Recommended Posts

[code=php:0]
$sql = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";

if ($name == "reg") {
$query = mysql_query( $sql ) or die(mysql_error());
} else {
[/code]

i get this error:
[quote]
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 'VALUES('0', dfg', 'fdg', 'gfdg', 'gfd', '6289f8aefb7e446ab0a0f10d027e6c68', 'Aug' at line 1[/quote]

Share this post


Link to post
Share on other sites
You are missing one of your single quotes...the one first one on $first_name.

[code]$sql = "INSERT INTO $table_users VALUES('$userid', --> ' <-- $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";[/code]

Share this post


Link to post
Share on other sites
[quote author=newb link=topic=103656.msg412892#msg412892 date=1155174520]
[code=php:0]
$sql = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";

if ($name == "reg") {
$query = mysql_query( $sql ) or die(mysql_error());
} else {
[/code]

i get this error:
[quote]
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 'VALUES('0', dfg', 'fdg', 'gfdg', 'gfd', '6289f8aefb7e446ab0a0f10d027e6c68', 'Aug' at line 1[/quote]
[/quote]

You missed a quote, read your error next time.
[code=php:0]
INSERT INTO $table_users VALUES('$userid', $first_name',
[/code]

Share this post


Link to post
Share on other sites
ok i changed the query now to
[code=php:0]$sql = mysql_query("INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");[/code]

but now i get this error:
[quote]
Query was empty[/quote]

whats that mean :s

Share this post


Link to post
Share on other sites
Change it to this and let's see what the query string actually is.

[code]
$query = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";
echo $query;
$sql = mysql_query($query);
[/code]

Share this post


Link to post
Share on other sites
k the code is this:
[code=php:0]
$query = mysql_query("INSERT INTO $table_users VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");

if ($name == "reg") {
echo $query;
$sql = mysql_query($query) or die(mysql_error());
} else {
[/code]

all it did was give me
[quote]
Query was empty[/quote]

Share this post


Link to post
Share on other sites
No, no, no......the first line should just be
[code]
$query = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";
[/code]

Share this post


Link to post
Share on other sites
http://www.tizag.com/mysqlTutorial/mysqlinsert.php

Any reason why you don't specify what fields you want the data inserted into?

Share this post


Link to post
Share on other sites
[quote author=newb link=topic=103656.msg412915#msg412915 date=1155176028]
why should i.
[/quote]

Good practice maybe. What are you going to do when you want to add a new field to your database table?  Go back and edit every instance of the insert query so you get the right data in the right place?

Share this post


Link to post
Share on other sites
[code=php:0]
$query = mysql_query("INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");
[/code]

didnt help, still getting same error.

Share this post


Link to post
Share on other sites
Make a useful modification to your code so that you can see what's happening. Report ALL the output you get.

[code]$query = "INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);[/code]

Share this post


Link to post
Share on other sites
now i get this error msg with ur modifcation:

[quote]Error: Query was empty with query
[/quote]

Share this post


Link to post
Share on other sites
Can you put the "echo $query" in so we can see what the string is that you are actually passing to mysql_query()?

Share this post


Link to post
Share on other sites
i did, and it didnt echo anything

heres my code:
[code=php:0]
$query = mysql_query("INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");
echo $query;
$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
[/code]

Share this post


Link to post
Share on other sites
Ok....

Look closely.  Change your code to this.  Exactly this. Do not add anything, do not take anything away.

[code]
$query = "INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";
echo $query;
$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
[/code]

And now let's see what the actual query string is.

Share this post


Link to post
Share on other sites
now i get this error message:
[quote]
INSERT INTO (id, first_name, last_name, email_address, username, password, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', '4e9ebbae28f66d96998f49edc51ebcde', 'August 9, 2006, 9:58 pm')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 '(id, first_name, last_name, email_address, username, password, signup_date) VALU' at line 1 with query INSERT INTO (id, first_name, last_name, email_address, username, password, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', '4e9ebbae28f66d96998f49edc51ebcde', 'August 9, 2006, 9:58 pm')[/quote]

Share this post


Link to post
Share on other sites
Username and password are reserved words. Put backticks around them if you must use those column names.

[code]
$query = "INSERT INTO $table_users (id, first_name, last_name, email_address, `username`, `password`, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";
echo $query;
$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
[/code]

Share this post


Link to post
Share on other sites
didnt help, same error i believe.
[quote]INSERT INTO (id, first_name, last_name, email_address, `username`, `password`, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', 'c43f0cf37469a3f1b20342132b0451de', 'August 9, 2006, 10:02 pm')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 '(id, first_name, last_name, email_address, `username`, `password`, signup_date) ' at line 1 with query INSERT INTO (id, first_name, last_name, email_address, `username`, `password`, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', 'c43f0cf37469a3f1b20342132b0451de', 'August 9, 2006, 10:02 pm')[/quote]

Share this post


Link to post
Share on other sites
just to be sure, just ran the query in phpMyAdmin, and it executed properly...so its definitely something with php :s

phpMyAdmin returned this:
[quote]
Inserted rows: 1
Inserted row id: 1 (Query took 0.0003 sec)
SQL query: INSERT INTO p16_users( id, first_name, last_name, email_address, `username` , `password` , signup_date )
VALUES (
'$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today'
)
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.