Jump to content


Photo

help, script error!


  • Please log in to reply
26 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 01:48 AM

$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 {

i get 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 'VALUES('0', dfg', 'fdg', 'gfdg', 'gfd', '6289f8aefb7e446ab0a0f10d027e6c68', 'Aug' at line 1



#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 01:53 AM

You are missing one of your single quotes...the one first one on $first_name.

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


#3 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 10 August 2006 - 01:53 AM

$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 {

i get 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 'VALUES('0', dfg', 'fdg', 'gfdg', 'gfd', '6289f8aefb7e446ab0a0f10d027e6c68', 'Aug' at line 1


You missed a quote, read your error next time.
INSERT INTO $table_users VALUES('$userid', $first_name',


#4 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 01:56 AM

ok i changed the query now to
$sql = mysql_query("INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");

but now i get this error:

Query was empty


whats that mean :s


#5 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 August 2006 - 01:59 AM

Means it didnt return any rows... AKA its empty
Why doesn't anyone ever say hi, hey, or whad up world?

#6 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 10 August 2006 - 02:00 AM

Change it to this and let's see what the query string actually is.

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

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 02:02 AM

You all are still missing the single quote before $first_name.

#8 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:04 AM

hmm didnt echo anything

#9 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:05 AM

k the code is this:
$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 {

all it did was give me

Query was empty



#10 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 10 August 2006 - 02:09 AM

No, no, no......the first line should just be
$query = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 August 2006 - 02:11 AM

http://www.tizag.com...mysqlinsert.php

Any reason why you don't specify what fields you want the data inserted into?
Legend has it that reading the manual never killed anyone.
My site

#12 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:13 AM

why should i.

#13 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 August 2006 - 02:15 AM

why should i.


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?
Legend has it that reading the manual never killed anyone.
My site

#14 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:16 AM

$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')");

didnt help, still getting same error.



#15 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 August 2006 - 02:20 AM

Make a useful modification to your code so that you can see what's happening. Report ALL the output you get.

$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);

Legend has it that reading the manual never killed anyone.
My site

#16 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:24 AM

now i get this error msg with ur modifcation:

Error: Query was empty with query



#17 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 10 August 2006 - 02:29 AM

Can you put the "echo $query" in so we can see what the string is that you are actually passing to mysql_query()?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#18 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:47 AM

i did, and it didnt echo anything

heres my code:
$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);


#19 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 10 August 2006 - 02:55 AM

Ok....

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

$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);

And now let's see what the actual query string is.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#20 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 10 August 2006 - 02:57 AM

now i get this error message:

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')






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users