View Full Version : mysql insert error

09-24-2010, 03:51 PM
Hi. I think you all know me by now so I'll cut to the chase.

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$sql="INSERT INTO $tbl_name(topic, detail, datetime)VALUES('$name', '$detail', NOW())";

echo("I have failed you master.");}

Displayed error: "I have failed you master." Anyone know a possible cause? Thanks. Bye.

09-24-2010, 04:00 PM
Instead of "I have failed you master", get the PHP to echo the $sql string that you're sending to the database.

As an aside, dropping unsanitised input straight into a database leaves you wide open to a SQL injection attack. At the very least, wrap $name and $detail in mysql_real_escape_string() (http://php.net/manual/en/function.mysql-real-escape-string.php),

09-24-2010, 04:05 PM
$result=mysql_query($sql) or die(mysql_error());

it's your responsibility to die(), if necessary!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum