Wednesday, 15 June 2011

php - Could not update data: SQL syntax error in my update command -



php - Could not update data: SQL syntax error in my update command -

just got error after fixing code, please consider userid in database set '0'!

outprint:

userid: '23' itemid: '8204'

update booking set userid ='23' itemid ='8204'

(error:) not update data: have error in sql syntax; check manual corresponds mysql server version right syntax utilize near '1' @ line 1

updated php code sec time:

<?php $con = mysql_connect("localhost", "root", "") or die(' not connect'); $db = mysql_select_db('book1', $con); if (isset($_get["userid"]) && isset($_get["itemid"])){ $userid= (int)$_get["userid"]; $itemid= (int)$_get["itemid"]; $test = "userid: '$userid' itemid: '$itemid'"; echo $test; echo "<br>"; } if (!$con) { die('could not connect: '.mysql_error()); } echo("update booking set userid ='$userid' itemid ='$itemid'"); echo "<br>"; $upd = mysql_query("update booking set userid ='$userid' itemid ='$itemid'"); $retval = mysql_query($upd, $con); if(!$retval){ die('could not update data: '.mysql_error()); } echo "updated info successfully\n"; $sql = mysql_query("select * booking"); if($sql === false) { die(mysql_error()); } echo '<table class="fixed"> <tr> <th>itemid</th> <th>employee id</th> </tr>'; while($row = mysql_fetch_array($sql)) { echo "<tr>"; echo"<td>".$row['itemid']."</td>"; echo"<td>".$row['userid']."</td>"; echo "</tr>"; }

?>

make sure getting $userid , $itemid perfectly.

then have @ $upd variable. running mysql_query. alter $upd to,

$upd = "update booking set userid ='$userid' itemid ='$itemid'";

then condition,

$retval = mysql_query($upd, $con); if(!$retval){ die('could not update data: '.mysql_error()); } else { .... }

it may prepare error.

php mysql

No comments:

Post a Comment