mysql Query format wrong

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

mysql Query format wrong

Post by danharibo »

Code: Select all

$sql = "INSERT INTO guestbook (name,comment,e-mail) VALUES ('$name','$comment','$email')";
Whats wrong with it? Mysql Don't like it :( and i can't see anyhing wrong with it
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Maybe mysql wants to tell you something about the query

Code: Select all

$sql = "INSERT INTO guestbook (name,comment,e-mail) VALUES ('$name','$comment','$email')";
$result = mysql_query($sql, $dblink) or die(mysql_error() . ' : ' . $sql);
see http://de2.php.net/mysql_error

My guess: dashes are not allowed in un-quoted field names. e-mail :arrow: `e-mail`
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

oh yeah, i forgot about that ( :roll: )
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

mysql_error shows nothing :?:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And this one

Code: Select all

$sql = "INSERT INTO guestbook (name,comment,e-mail) VALUES ('$name','$comment','$email')";
echo 'mysql_query: ', $sql; flush();
$result = mysql_query($sql, $dblink);
if ( false===$result) {
	die(mysql_error() . ' : ' . $sql);
}
else {
	echo 'query successful, affected rows: ', mysql_affected_rows();
}
prints ...?
Post Reply