Query was empty PHP error

后端 未结 2 483
花落未央
花落未央 2021-01-24 06:05

I am trying to build a cart using MySQL. I keep getting this error \'Query was empty\' when I run this code. Please help I\'ve tried several things such as putting the variables

2条回答
  •  清歌不尽
    2021-01-24 06:24

    What do you try to achieve with this line?

    $result = mysql_query($query);
    

    Just delete it and change the line above to

    $result = mysql_query('insert into cart values('.$user.','.$itemNum.','.$name.', '.$image.','.$quantity.', '.$price.')'); 
    

    [Edit]

    Btw. you are forgetting the " (quotes) inside the query which causes an sql error to occur, leading to $query = false (see manual). $query (false) then gets converted to string, resulting in '' (an empty string) which you pass to mysql_query and that generates an "Query was empty"-Message, as it should because you tried to send an empty query.

提交回复
热议问题