Alidad Posted January 4, 2014 Share Posted January 4, 2014 hi, I tried to change update query from mysql to mysqli, at first under mysql is works great to update into mysql database but when i changed to mysqli is not doing update it. can anyone tell me what did i missed! under mysql <?php include('db.php'); if(isset($_GET['status'])) { $status1=$_GET['status']; $select=mysql_query("select * from manage where id='$status1'"); while($row=mysql_fetch_object($select)) { $status_var=$row->status; if($status_var=='0') { $status_state=1; } else { $status_state=0; } $update=mysql_query("update manage set status='$status_state' where id='$status1' "); if($update) { header("Location:index.php"); } else { echo mysql_error(); } } ?> <?php } ?> and under mysqli <?php include('db.php'); $dbcs = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database); if(isset($_GET['status'])) { $status1=$_GET['status']; $sql = "select * from product where product_id='$status1'"; $result=mysqli_query($dbcs,$sql); while($row=mysqli_fetch_object($result)) { $status_var=$row->status; if($status_var=='0') { $status_state=1; } else { $status_state=0; } $mysqli->query("UPDATE product set status='$status_state' where product_id='$status1' "); if($mysqli) { header("Location:item.php"); } else { echo mysqli_error(); } } ?> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/285076-why-could-not-be-able-to-update-it/ Share on other sites More sharing options...
requinix Posted January 4, 2014 Share Posted January 4, 2014 Find your php.ini and set error_reporting = -1 display_errors = onrestart your web server, and try your script. Hint: a problem (there may be others I didn't see at a glance) is with $mysqli->query("UPDATE product set status='$status_state' where product_id='$status1' "); Link to comment https://forums.phpfreaks.com/topic/285076-why-could-not-be-able-to-update-it/#findComment-1463785 Share on other sites More sharing options...
jazzman1 Posted January 4, 2014 Share Posted January 4, 2014 Also, don't mixing both styles (object-oriented and procedural). Even though it's possible is not recommended for code clarity and coding style reasons. Link to comment https://forums.phpfreaks.com/topic/285076-why-could-not-be-able-to-update-it/#findComment-1463786 Share on other sites More sharing options...
Alidad Posted January 4, 2014 Author Share Posted January 4, 2014 i put this code on the top of page <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> but still not showing any errors. any other idea of errors! please help thanks. AM Link to comment https://forums.phpfreaks.com/topic/285076-why-could-not-be-able-to-update-it/#findComment-1463789 Share on other sites More sharing options...
mac_gyver Posted January 4, 2014 Share Posted January 4, 2014 i'm going to guess you are not seeing any php errors because you are not requesting the page with a ?status=n on the url and most of the logic is being skipped over. you might also have output_buffering turned on in your php.ini and any output from php or your code is being discard. btw - to toggle a value between back and forth between zero and one, you don't need all that logic - include 'db.php'; $mysqli = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database); if($mysqli->connect_error){ die("Connect Error ($mysqli->connect_errno) $mysqli->connect_error"); } $status = isset($_GET['status']) ? (int)$_GET['status'] : false; if($status) { if(!$mysqli->query("UPDATE product set status = NOT status where product_id=$status")){ die("Query failed: $mysqli->error"); } header("Location:item.php"); } Link to comment https://forums.phpfreaks.com/topic/285076-why-could-not-be-able-to-update-it/#findComment-1463790 Share on other sites More sharing options...
Barand Posted January 4, 2014 Share Posted January 4, 2014 $dbcs = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database); $mysqli->query("UPDATE product set status='$status_state' where product_id='$status1' "); Link to comment https://forums.phpfreaks.com/topic/285076-why-could-not-be-able-to-update-it/#findComment-1463802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.