Jump to content

Why could not be able to update it!


Alidad

Recommended Posts

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
Share on other sites

Find your php.ini and set

error_reporting = -1
display_errors = on
restart 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
Share on other sites

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
Share on other sites

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.