-2

i'm trying to insert some records into the db and i'm getting this error: Query was empty

$data= json_decode(file_get_contents("php://input"));
$usercomment= mysql_real_escape_string($data->usercomment);
$wardrobe= mysql_real_escape_string($data->wardrobe);
$ctype= mysql_real_escape_string($data->ctype);
$pic= mysql_real_escape_string($data->pic);
$vtype= mysql_real_escape_string($data->vtype);

$query=mysql_query ("INSERT INTO db.comment(`comment`,`pic`,`wardrobe`,`comment_type`,`vtype`)
VALUES('".$usercomment."','".$pic."','".$wardrobe."','".$ctype."','".$vtype."')");
$Result1 = mysql_query($query, $dbcon) or die(mysql_error());
user6579134
  • 749
  • 3
  • 10
  • 35

2 Answers2

1

$query is already a mysql_query, so you can't add it inside the other mysql_query.

You can make $query be the string for the mysql_query below it.

$query = "INSERT INTO db.comment(`comment`,`pic`,`wardrobe`,`comment_type`,`vtype`)    VALUES('".$usercomment."','".$pic."','".$wardrobe."','".$ctype."','".$vtype."')";

$result1 = mysql_query($query, $dbcon) or die(mysql_error());

Also, don't use the mysql_* functions, use mysqli_* instead.

See this answer for more details on why.

Community
  • 1
  • 1
Phiter
  • 14,570
  • 14
  • 50
  • 84
0

I have modified your code.. try this

data= json_decode(file_get_contents("php://input"));
$usercomment= mysql_real_escape_string($data->usercomment);
$wardrobe= mysql_real_escape_string($data->wardrobe);
$ctype= mysql_real_escape_string($data->ctype);
$pic= mysql_real_escape_string($data->pic);
$vtype= mysql_real_escape_string($data->vtype);

$query="INSERT INTO db.comment(`comment`,`pic`,`wardrobe`,`comment_type`,`vtype`)
VALUES('".$usercomment."','".$pic."','".$wardrobe."','".$ctype."','".$vtype."')";
$Result1 = mysql_query($query) or die(mysql_error());
Prajwal K M
  • 157
  • 1
  • 2
  • 17