Page 1 of 1

Code error, can someone help?

Posted: Fri Jan 13, 2006 5:07 am
by okanem
I receive the following 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 ',)' at line 1
********

when running this code

Code: Select all

<?php
@mysql_connect("localhost", "root", "123") or die("Cannot connect to DB!"); 
@mysql_select_db("cws") or die("Cannot select DB!"); 
$sql="INSERT INTO users (username, password, email) VALUES (".$username.",".$password.",".$email.")"; 
$r = mysql_query($sql); 
if(!$r) { 
  $err=mysql_error(); 
  print $err; 
  exit(); 
} 

?>
Can someone help me eradicate the SQL syntax error

This might work

Posted: Fri Jan 13, 2006 5:11 am
by sp2hari
try giving this sql query

Code: Select all

$sql="INSERT INTO users (username, password, email) VALUES ('".$username."','".$password."','".$email."')";
Just added a few single quotes

Re: Code error, can someone help?

Posted: Fri Jan 13, 2006 5:11 am
by steven72
okanem wrote:I receive the following 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 ',)' at line 1
********

when running this code

Code: Select all

<?php
@mysql_connect("localhost", "root", "123") or die("Cannot connect to DB!"); 
@mysql_select_db("cws") or die("Cannot select DB!"); 
$sql="INSERT INTO users (username, password, email) VALUES ('".$username."','".$password."','".$email."')"; 
$r = mysql_query($sql); 
if(!$r) { 
  $err=mysql_error(); 
  print $err; 
  exit(); 
} 

?>
Can someone help me eradicate the SQL syntax error
How about now?

Posted: Fri Jan 13, 2006 5:27 am
by okanem
that works fine, thanks steven72 and sp2hari

Okanem

Posted: Fri Jan 13, 2006 5:36 am
by JayBird
what's this new trend im starting to see with everyone supressing error messages with '@'

:evil:

How to make errors show

Posted: Fri Jan 13, 2006 6:46 am
by sp2hari
I am working in LAMP server sysem.
My server soes not show the error neither the warnings :cry:
do you have any idea where to change the settings
I tried a lot but still unsuccessfull :cry:

Posted: Fri Jan 13, 2006 9:00 am
by feyd
error_reporting and display_errors in php.ini control them..

Posted: Fri Jan 13, 2006 9:48 am
by Chris Corbyn
Pimptastic wrote:what's this new trend im starting to see with everyone supressing error messages with '@'

:evil:
I know, I've noticed this too. Bad, bad..... bad... programming :evil:

Posted: Fri Jan 13, 2006 12:57 pm
by fendtele83
i've seen this a lot in php books, especially by Apress... i think what they're trying to do is get people to develope they're own way of error reporting, rather than relying on apache to do it for them.

Posted: Fri Jan 13, 2006 2:54 pm
by foobar
fendtele83 wrote:i think what they're trying to do is get people to develope they're own way of error reporting, rather than relying on apache to do it for them.
That'll be difficult if you don't allow the error to be triggered. You'd have to check all data before passing it on to a function. What a pain in the a$$.

One more thing: Apache has nothing to do with non-HTTP errors. That's done by the PHP engine.

Posted: Fri Jan 13, 2006 3:07 pm
by fendtele83

Code: Select all

@mysql_query($query) or die(customErrFunc())
would allow you to customize the error message

Posted: Fri Jan 13, 2006 3:11 pm
by timvw
Would it? It would force me to die.. I don't see the advantage of mysql_whatever() or trigger_error(...);

Posted: Sat Jan 14, 2006 2:13 pm
by fendtele83
maybe i'm wrong... but it works fine for what I'm doing...

Posted: Sat Jan 14, 2006 8:16 pm
by Jenk
timvw wrote:Would it? It would force me to die.. I don't see the advantage of mysql_whatever() or trigger_error(...);
using a customised error handler is a perfect reason to use "or trigger_error();".