ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

PHP code headache



Keep getting the "Error Editing" message, which is really really annoying me as I can't see what's wrong. This page is posted an array from a previous page, which is 'print_r'ing correctly. It breaks before the update. Have I missed something really obvious?
PHP:
    if (isset($_POST[id])){
                print_r ($_POST);
                print_r ($_GET);
            //update
            $queryupd = "UPDATE products SET name = '$_POST[name]', price = '$_POST[price]', stock = '$_POST[stock]', desc = '$_POST[desc]', category = '$_POST[category]' WHERE id = '$_POST[id]'";
            $resultupd = mysql_query($queryupd);
            //update the entry
            if($resultupd){
            $message = "Product Edited!";
            header("Location: editProduct.php?message=$message");
            }else{
            $message = "Error Editing!";
echo $message;
            };
    }else{
        echo 'id not set';
                };
 
  DCi
maybe something to do with the space in message? try $message = "Product%20Edited!";

or maybe

header("Location: editProduct.php?message=".$message);

I'm no expert, just guessing really!
 
maybe something to do with the space in message? try $message = "Product%20Edited!";

or maybe

header("Location: editProduct.php?message=".$message);

I'm no expert, just guessing really!

The messages are working fine, it's the UPDATE that's not working.
 
  DCi
surely if you are getting "error editing" then it is failing on the first part of that particular if statement?

anyway if you are certain your query has a fault then do this:

$resultupd = mysql_query($queryupd) or echo mysql_error();


at least I think that is the function that will tell you what is wrong in your query.
 
This is the line that's breaking the code:
PHP:
if($resultupd){
because the query is not execting.

I've just tried a cutdown query of:
PHP:
$queryupd = "UPDATE products SET name = '$_POST[name]' WHERE id = '$_POST[id]'";
and this has NOT worked fine - says "Product Edited" but values in DB are unchanged ahhhhhhhh!
 

KDF

  Audi TT Stronic
Keep getting the "Error Editing" message, which is really really annoying me as I can't see what's wrong. This page is posted an array from a previous page, which is 'print_r'ing correctly. It breaks before the update. Have I missed something really obvious?
PHP:
    if (isset($_POST[id])){
                print_r ($_POST);
                print_r ($_GET);
            //update
            $queryupd = "UPDATE products SET name = '$_POST[name]', price = '$_POST[price]', stock = '$_POST[stock]', desc = '$_POST[desc]', category = '$_POST[category]' WHERE id = '$_POST[id]'";
            $resultupd = mysql_query($queryupd);
            //update the entry
            if($resultupd){
            $message = "Product Edited!";
            header("Location: editProduct.php?message=$message");
            }else{
            $message = "Error Editing!";
echo $message;
            };
    }else{
        echo 'id not set';
                };

Try,

PHP:
    if (isset($_POST[id])){
                print_r ($_POST);
                print_r ($_GET);
            //update
            $queryupd = "UPDATE products SET name = '".$_POST[name]."', price = '".$_POST[price]."', stock = '".$_POST[stock]."', desc = '".$_POST[desc]."', category = '".$_POST[category]."' WHERE id = '".$_POST[id]."'";
            $resultupd = mysql_query($queryupd) or die("Error: Your Query: " . $queryupd . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());
            //update the entry
            if($resultupd){
            $message = "Product Edited!";
            header("Location: editProduct.php?message=$message");
            }else{
            $message = "Error Editing!";
echo $message;
            };
    }else{
        echo 'id not set';
                };

I've enclosed the variables and if that doesn't fix it i've added a 'or die' clause to the mysql query that will give you an informative error message on failure, post that error message up here and i will be able to help you.

Also you should encode the data coming in to stop sql injection attacks, but if its just a demo script you wont need that.
 


Top