azparties Posted October 12, 2013 Share Posted October 12, 2013 I'm having issues converting to MySQLI, can someone take a look for me. Thanks, salestatusupdateplusone.php Quote Link to comment Share on other sites More sharing options...
vinny42 Posted October 12, 2013 Share Posted October 12, 2013 What kind of issues are you having? Your code seems odd by the way, you have a huge switch with 30 cases that just return the value plus one, so what's the use of that switch? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 12, 2013 Share Posted October 12, 2013 (edited) First issue localhost should be in quotes $con=mysqli_connect(localhost,$username,$password, $database); Second issue the the variables $quantity and $id do not appear to be defined any where. Where are these variables defined? Third issue $mysqli->query("UPDATE sale SET `quantity`='$ud_quantity' WHERE `index`='$id'"; The $mysqli object doesn't exist. You're using the procedural function to connect to mysq there for you should use the procedural mysqli_query function. Also you where missing the closing parenthesis at the end of the line too. The above line should be mysqli_query($con, "UPDATE sale SET `quantity`='$ud_quantity' WHERE `index`='$id'"); Fourth issue printf("Affected rows (UPDATE): %d\n", $mysqli->affected_rows or die(mysql_error()); The or die() clause is in the wrong place, it should be after the mysqli_query() call. mysql_error should be mysqli_error() As a side note the switch statement could be rewritten as a simple if/else statement if($quantity >= 0 && $quantity <= 30) $ud_quantity = $quantity + 1; else $ud_quantity = 'ERR'; Edited October 12, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Barand Posted October 12, 2013 Share Posted October 12, 2013 (edited) You're using the procedural function to connect to mysq there for you should use the procedural mysqli_query function. You can mix-and-match object methods and procedural functions. This runs fine $db = mysqli_connect(HOST, USERNAME, PASSWORD, DATABASE); // using defined constants $res = $db->query("SELECT COUNT(*) FROM votes") or die($db->error); $row = mysqli_fetch_row($res); echo $res->num_rows; // --> 1 echo $row[0]; // --> 182685 edit: You use the object method or pass the object to the procedural function Edited October 12, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 12, 2013 Share Posted October 12, 2013 You can mix-and-match object methods and procedural functions. This runs fineDidn't think that was possible. Seems a bit broken to me. Quote Link to comment Share on other sites More sharing options...
kicken Posted October 13, 2013 Share Posted October 13, 2013 Didn't think that was possible. Seems a bit broken to me. The procedural functions are just small wrappers basically, eg: function mysqli_query($obj, $query){ return $obj->query($query); } Quote Link to comment Share on other sites More sharing options...
Barand Posted October 13, 2013 Share Posted October 13, 2013 The procedural functions are just small wrappers basically, eg: function mysqli_query($obj, $query){ return $obj->query($query); } I suspected that that were the case, which would make the object versions minimally more efficient than the procedural ones. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.