Code error, can someone help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
okanem
Forum Newbie
Posts: 9
Joined: Thu Jan 12, 2006 6:26 am

Code error, can someone help?

Post 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
User avatar
sp2hari
Forum Newbie
Posts: 14
Joined: Fri Jan 13, 2006 3:54 am

This might work

Post 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
steven72
Forum Newbie
Posts: 3
Joined: Fri Jan 13, 2006 4:21 am

Re: Code error, can someone help?

Post 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?
User avatar
okanem
Forum Newbie
Posts: 9
Joined: Thu Jan 12, 2006 6:26 am

Post by okanem »

that works fine, thanks steven72 and sp2hari

Okanem
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what's this new trend im starting to see with everyone supressing error messages with '@'

:evil:
User avatar
sp2hari
Forum Newbie
Posts: 14
Joined: Fri Jan 13, 2006 3:54 am

How to make errors show

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

error_reporting and display_errors in php.ini control them..
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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:
User avatar
fendtele83
Forum Commoner
Posts: 27
Joined: Tue Oct 25, 2005 2:21 pm
Location: Woodbridge, NJ

Post 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.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
User avatar
fendtele83
Forum Commoner
Posts: 27
Joined: Tue Oct 25, 2005 2:21 pm
Location: Woodbridge, NJ

Post by fendtele83 »

Code: Select all

@mysql_query($query) or die(customErrFunc())
would allow you to customize the error message
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Would it? It would force me to die.. I don't see the advantage of mysql_whatever() or trigger_error(...);
User avatar
fendtele83
Forum Commoner
Posts: 27
Joined: Tue Oct 25, 2005 2:21 pm
Location: Woodbridge, NJ

Post by fendtele83 »

maybe i'm wrong... but it works fine for what I'm doing...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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();".
Post Reply