samedi 29 août 2015

If statement condition is not satisfied, do not return error?

I have a variable $cc, this variable stores checkbox selections in this fashion:

251000-1,252000-2,252012-1 ... etc (Depending on how many choices)

I have successfully figured out how to store the data in multiple tables using a strpos if condition :

if (strpos($b,'251000') !== false) {
        $sql3="INSERT INTO engworkshops (studentid, ckb)
            VALUES ('$studentid', '$cc')";
            echo 'true';
        }


        if (strpos($b,'252000') !== false) {
        $sql4="INSERT INTO engdrwnga (studentid, ckb)
            VALUES ('$studentid', '$cc')";
            echo 'true';
        }


        if (strpos($b,'252012') !== false) {
        $sql5="INSERT INTO engdrwngb (studentid, ckb)
            VALUES ('$studentid', '$cc')";
            echo 'true';
        }
     if (!mysqli_query($dbcon,$sql3)) 
       {
          die('Error: ' . mysqli_error($dbcon));
       }
       if (!mysqli_query($dbcon,$sql4)) 
       {
          die('Error: ' . mysqli_error($dbcon));
       }
         if (!mysqli_query($dbcon,$sql5)) 
       {
          die('Error: ' . mysqli_error($dbcon));
       }

The problem lies here : The logic of this code only works if all three if conditions are satisfied meaning that if my "variable $cc" contains 251000 and 252000 and 252012 , it stores the data in each table with no problems what so ever.

I tried nested if statements elseif statements both didnt work

My guess is that the way I'm defining my insert statements and checking for errors in them if they are not executed is causing the problem , How can I fix this ?

Aucun commentaire:

Enregistrer un commentaire