hello,
i have below code and i need to change the status to inactive when i press the delete button. it happens that when i use the code below, the status does not change at all. can anyone tell me where am having an error in the code?

<?php

session_start();

include_once("db_connect.php");

if(isset($_POST['delete']))
{
    $prod_id=$_POST['prod_id'];
    $prod_name=$_POST['prod_name'];
    $prod_brand=$_POST['prod_brand'];
    $prod_desc=$_POST['prod_desc'];
    $prod_w_c=$_POST['prod_w_c'];

        //updating the table

        $result=mysql_query("UPDATE tblproduct SET status='inactive' WHERE prod_id='".$prod_id."';");

        header("Location: del_updprod.php");
    }

?>
<?php

$prod_id = $_GET['prod_id'];

$result=mysql_query("SELECT * FROM tblproduct where prod_id = ".$prod_id." AND status = 'active'") or die(mysql_error());

?>
<html>
<title>Delete Product</title>
<body background="Images/contentbg.jpg">
<a href="del_updprod.php"><img src="Images/back button.png" width="100" /></a>
<br/><br/>
<form name="edit" method="post" action="del_prod.php">
<table align="center" border="0">
<?php
while($res=mysql_fetch_array($result))
{
    $prod_name=$res['prod_name'];
    $prod_brand=$res['prod_brand'];
    $prod_desc=$res['prod_desc'];
    $prod_w_c=$res['prod_w_c'];

?>
   <tr> 
    <td>Product Name</td>
    <td>
        <input type="text" name="prod_name" value = "<?php echo $prod_name;?>"> </td>
  </tr>
  <tr> 
    <td>Product Brand</td>
    <td>
        <input type="text" name="prod_brand" value = "<?php echo $prod_brand;?>">     </td>
  </tr>
  <tr> 
    <td>Product Description</td>
    <td>
        <textarea rows="5" cols="50" name="ret_city"><?php echo $prod_desc;?></textarea>  </td>
  </tr>
  <tr> 
    <td>Product Weight/Capacity</td>
    <td>
        <input type="text" name="prod_w_c" value = "<?php echo $prod_w_c;?>">     </td>
  </tr>
  <?php } ?> 
   <tr>
    <td><input type="submit" name="delete" value="Delete"></td>
  </tr>
</table>
</form>

</body>
</html>
Member Avatar for iamthwee

More information please, where does it fail what are the errors

mysql_query expects a string that does not end in a semi-colon.

Put this temporary debug code on line 14.

die("UPDATE tblproduct SET status='inactive' WHERE prod_id='".$prod_id."';");

It will display the query and stop the script. Now copy the query in phpmyadmin and test it.

i receive no errors.

which mysql_query do you mean please?

I suspect that line 7 results in false and that is why nothing is happening. You can put in an else block and out something in there to help you figure out if the statment is false like a echoing something just to test.

Attn broj1
hello my dear friend...please help out
have a loook at the attachment. i sent you a private message as well.

My comment was in relation to line 17 - there is a ; character at the end of the argument which is invalid.

even though i removed that invalid character the issue persists. the status does not change to inactive in the database table.

What was displayed after the code I gave you in my last post (please post the output here)?

die("UPDATE tblproduct SET status='inactive' WHERE prod_id='".$prod_id."';");

You can make this code a bit simpler:

die("UPDATE tblproduct SET status='inactive' WHERE prod_id='$prod_id'");

adaaf5db1246d14f3d49f2b1c09d1756 Here are my few suggestions,

1) Do check whether, error logs are ON, or try to add these lines to enable,

    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);

2) Replace all $_POST with $_REQUEST (Just a try)
3) Add backtick (above tab key & near to 1 key) symbol in all your queries where, field names are declared Ex: Ref attachment Eg. 1

4) If not, echo the queries & execute the query in your PhpMyadmin & check, Ex: Ref attachment Eg. 2

Hope, it will help you somewhat... :)

Add backtick (above tab key & near to 1 key) symbol in all your queries where, field names are declared Ex: Ref attachment Eg. 1

@mrvijayakumar: great thinking :-). The queries (lines 17 and 27) contain a field named status which is a mysql keyword therefore it has to be enclosed with backticks.

So, line 17:

$result=mysql_query("UPDATE `tblproduct` SET `status`='inactive' WHERE `prod_id`='$prod_id'");

and line 27:

$result=mysql_query("SELECT * FROM `tblproduct` where `prod_id`='$prod_id' AND `status` = 'active'") or die(mysql_error());

A backtick on my keyboard is on alphanumeric 7 key (AltGr + 7 -> Space).

Member Avatar for diafol

A backtick on my keyboard is on alphanumeric 7 key (AltGr + 7 -> Space).

On mine, the key before the number #1 and then followed by any other input (alphanumeric/symbol/space) key.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.