-4

I put this code in my php file and it gives me the error syntax error, unexpected 'order' (T_STRING)

What am I doing wrong?

$sqldelreq="DELETE FROM `requests` WHERE tablecode = 1 and type = "order"";
        $result2=mysql_query($sqldelreq);
            if($result2)
            {
                header("Location: http://localhost/mjjapp/index.php");
            }
Loofer
  • 6,841
  • 9
  • 61
  • 102
jeiidii
  • 87
  • 1
  • 10

4 Answers4

2

I think the query should be:

"DELETE FROM `requests` WHERE tablecode = 1 and type = 'order'";

Please note the single quotes around order.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
Nikos
  • 3,267
  • 1
  • 25
  • 32
  • I am sorry I edited this answer for almost nothing. I gave you a down-vote earlier tonight considering your answer wrong when it was in fact in correct. When I realized it it was too late to retract my down-vote. After a few hours of feeling guilty when i just saw it i retracted my down-vote. – Hanky Panky Sep 21 '15 at 15:28
  • Hahah, no worries! I accept your apology but feel bad for your feeling guilty :) It's only stackoverflow :) Take care :) – Nikos Sep 21 '15 at 15:29
0

You should do proper escape

 $sqldelreq = "DELETE FROM `requests` WHERE `tablecode` = 1 and `type` = 'order'";

Also your if is invalid. It only means that query was successful if you wan't to check if any rows were deleted you need to check how many rows were affected with mysql_affected_rows() function.

Moreover, consider using mysqli or pdo. Mysql_* functions are deprecated.

Robert
  • 19,800
  • 5
  • 55
  • 85
0

Correct syntax usually goes a long way; try:

$sqldelreq = "DELETE FROM `requests` WHERE `tablecode` = 1 AND `type` = 'order';";
foxbeefly
  • 510
  • 3
  • 13
0

i found this running well thanks guys for ideas

$sqldelreq="DELETE FROM requests WHERE tablecode = 1 and type = 'order';";
jeiidii
  • 87
  • 1
  • 10