Jump to content

Recommended Posts

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 by Ch0cu3r
 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 by Barand

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.