Jump to content

help, script error!


newb

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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72213
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72221
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?
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72230
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.

Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72231
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72233
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72242
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.
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72243
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72245
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72246
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72247
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]
Link to comment
https://forums.phpfreaks.com/topic/17092-help-script-error/#findComment-72250
Share on other sites

Archived

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

×
×
  • Create New...

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.