IF Statement does not work in my situation

1307 views php
4

if (isset($_POST["submit2"])) {
    $uid = $_SESSION["uid"];
    $remove_id = $_POST["remove_id"];
    $sql = "DELETE FROM orders WHERE product_id = '$remove_id' AND user_id = '$uid'";
    $run_query = mysqli_query($link,$sql);
    $payment = $_POST["p_status"];
    $method = "Paypal";
    if ($payment == $method) {
        echo "Please contact the company";
    }
    else if ($run_query) {                                      
        echo "<meta http-equiv='refresh' content='0'>";
    }
}

My if statement doesnt work. it always continue to run_query.please help me thanks. p_status is "Paypal"

answered question

what is the result from echo $payment ?

the result is Paypal

well, thats weird. can i see the form before ?

$run_query = mysqli_query($link,$sql); is the statement that runs the query. The variable would be better named $queryRan

1 Answer

4

Your problem is that since your query has no errors in it, mysqli_query will return true every time you run the query, even if there are no rows to delete. What you need to do is check if any rows were deleted using mysqli_affected_rows instead:

if($payment == $method) {
    echo "Please contact the company";
} 
else if (mysqli_affected_rows($link) > 0) {                                       
    echo "<meta http-equiv='refresh' content='0'>";
}

posted this

Have an answer?

JD

Please login first before posting an answer.