-1

I've been looking at this for hours, and I can't find the problem as to why my sql insert won't work.

$body = "link test - 3!!!";
$userid = 1;
$cat_id = 3;
$user_url = "http://www.pizza.com";
$body = mysql_real_escape_string($body);

$sql = "insert into posts (userid, body, stamp, cat_id, link) values ($userid,$body,now(),$cat_id,$user_url)";

$result = mysql_query($sql);
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

2 Answers2

6

$body and $user_url are string but you didn't quote .

$sql = "insert into posts (userid, body, stamp, cat_id, link) values ($userid,'$body',now(),$cat_id,'$user_url')";

and quote any other fields that need it.

Musa
  • 96,336
  • 17
  • 118
  • 137
0

You also need to escape special characters in $body to avoid future problems.

$sql = "insert into posts (userid, body, stamp, cat_id, link) values ($userid, '".mysql_real_escape_string($body)."', '".now()."', $cat_id, '$user_url')";
Mario Radomanana
  • 1,698
  • 1
  • 21
  • 31