lundi 18 avril 2016

Very strange PHP issue. Conditions won't apply as they should

I have an SQL table called jobs that consists of a column titled 'jobID'. As a test, I need my code to let me know whether the jobID that has been entered already exists in the table.

What I'm getting now is, when i enter a jobID that I know is in the table, it returns "OLD", which is fine. But when I enter a new number, it doesn't return anything at all.

if (isset($_GET['customerName']) && isset($_GET['jobID'])) {
            $jobID = $_GET['jobID'];
            $customerName = $_GET['customerName'];
            $result = mysqli_query($con,"SELECT jobID FROM jobs WHERE jobID=$jobID");               

                while($row = mysqli_fetch_array($result)) {
                    $exist = $row['jobID'];
                if (isset($exist)) {
                    echo "OLD";
                    } else {
                    echo "NEW"; 
                } 
            } 
        }

Can anybody point out why that might be? I've also tested the PHP in the SQL table itself to see what it returns when I enter a new number and it returns an empty result, but even changing the if function to an empty test doesn't get the results to come up.

I've tried testing for whether the row exists, and it still doesn't return the two opposing results for when the condition is and isn't met.

Aucun commentaire:

Enregistrer un commentaire