php - Mupdate sql query return an error: limit 1 -


<?php  // find current order         $current_order_id = find_order_by_id($_get['order']);        if(!$current_order_id){          redirect_to("orders.php");        } ?>  <?php       $id = $current_order_id["id"];       $menu_name = $_post["menu_name"];       $address = $_post["address"];       $contact = $_post["contact"];       $transaction = $_post["transaction"];       $flemingia = $_post["flemingia"];       $goat_manual = $_post["goat_manual"];       $lbc_tracking_no = $_post["lbc_tracking_no"];       $visible = $_post["visible"];         $query  = "update orders set ";       $query .= "menu_name = '{$menu_name}', ";       $query .= "address = '{$address}', ";       $query .= "contact = {$contact}, ";       $query .= "transaction = '{$transaction}', ";       $query .= "flemingia = {$flemingia}, ";       $query .= "goat_manual = {$goat_manual}, ";       $query .= "lbc_tracking_no = {$lbc_tracking_no}, ";       $query .= "visible = {$visible} ";       $query .= "where id = {$id} ";       $query .= "limit 1";       $result = mysqli_query($connection, $query);       if($result){         die("database connection failed. " . mysqli_error($connection));       } ?> 

and error got: database connection failed:you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'limit 1' @ line 1

can explain why happen

i suspect pickup wrong id echo query , got! right id

output of query:

update orders set menu_name = '', address = '', contact = , transaction = '', flemingia = , goat_manual = , lbc_tracking_no = , visible = id = 20 limit 1

note: contact, flemingia, goat_manual, lbc_tracking_no, visible int

===============================update===================================

my form

<h1>create order : <?php echo $current_order_id["menu_name"]; ?></h1> <p class="error"><?php echo $message; ?></p> <form action="edit_order.php" method="post"> <p><span>name</span>: <input type="text" name="menu_name" value="<?php echo $current_order_id["menu_name"]; ?>" /> </p> <p><span>address</span>: <input type="text" name="address" value="<?php echo $current_order_id["address"]; ?>" /> </p> <p><span>contact number</span>: <input type="text" name="contact" value="<?php echo $current_order_id["contact"]; ?>" /> </p> <p><span>transaction</span>: <input type="text" name="transaction" value="<?php echo $current_order_id["transaction"]; ?>" /> </p> <p><span>flemingia</span>: <input type="text" name="flemingia" value="<?php echo $current_order_id["flemingia"]; ?>" /> </p> <p><span>goat manual</span>: <input type="text" name="goat_manual" value="<?php echo $current_order_id["goat_manual"]; ?>" /> </p> <p><span>lbc tracking no.</span>: <input type="text" name="lbc_tracking_no" value="<?php echo $current_order_id["lbc_tracking_no"]; ?>" /> </p> <p><span>visible</span>: <input type="radio" name="visible" value="0" <?php if($current_order_id["visible"] == 0){echo "checked";} ?> />no <input type="radio" name="visible" value="1" <?php if($current_order_id["visible"] == 1){echo "checked";}?> />yes </p> <input class="submit_btn" type="submit" name="submit" value="edit order" /> </form>

this function

<?php      function redirect_to($new_location){        header("location:" . $new_location);        exit;      }      function confirm_query($result_set){        if(!$result_set){       die("database connection failed. ");     }     }      function find_all_order(){       global $connection;        $query  = "select * ";       $query .= "from orders";       $order_set = mysqli_query($connection, $query);       confirm_query($order_set);       return  $order_set;     }     function find_order_by_id($order_id){       global $connection;        $query  = "select * ";       $query .= "from orders ";       $query .= "where id = {$order_id} ";       $query .= "limit 1";       $orderset = mysqli_query($connection, $query);       if(!$orderset){         die("database connection failed:" . mysqli_error($connection));       }       if($order = mysqli_fetch_assoc($orderset)){       return $order;       }else{         return null;       }     }   ?> 

i think know problem is. need use multi_query() function.

try this:

if(!$connection->multi_query($query)){  echo "multi query failed: (" . $connection->errno . ") " . $connection->error; } 

instead of $result = mysqli_query($connection, $query);


edit

try method then:

 $query  = "update orders set menu_name = '$menu_name', address = '$address',   contact = $contact, transaction = '$transaction', flemingia = $flemingia,   goat_manual = $goat_manual, lbc_tracking_no = $lbc_tracking_no, visible = $visible    id = $id limit 1";   $result = mysqli_query($connection, $query);    if(!$result){     die("database connection failed. " . mysqli_error($connection));   }    else{   echo "success";   } 

or:

 $query  = "update orders set menu_name = '".$menu_name."', address = '".$address."',   contact = $contact, transaction = '".$transaction."', flemingia = $flemingia,   goat_manual = $goat_manual, lbc_tracking_no = $lbc_tracking_no, visible = $visible    id = $id limit 1";   $result = mysqli_query($connection, $query);    if(!$result){     die("database connection failed. " . mysqli_error($connection));   }    else{   echo "success";   } 

however, if of entries contain hyphens, factor.


original answer

you have quotes missing of variables:

{$flemingia} - {$goat_manual} - {$lbc_tracking_no} - {$visible}

  $query  = "update orders set ";   $query .= "menu_name = '{$menu_name}', ";   $query .= "address = '{$address}', ";   $query .= "contact = {$contact}, ";   $query .= "transaction = '{$transaction}', ";   $query .= "flemingia = '{$flemingia}', ";   $query .= "goat_manual = '{$goat_manual}', ";   $query .= "lbc_tracking_no = '{$lbc_tracking_no}', ";   $query .= "visible = '{$visible}' ";   $query .= "where id = {$id} ";   $query .= "limit 1";   $result = mysqli_query($connection, $query); 

edit: deleted {$contact} list, since op said int

however, may need put them in, since contact = , part of error message, along others.

your {$id} did not have , shows correctly in echo'ed query.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -