Ryan Turnbull
Ryan Turnbull

Reputation: 3934

Simple passing of input to a button onClick

So i'm creating a taxi booking app ( mock-up project ) and am implementing a search bar for searching through a database via sql. I've got everything working, but now i want to check if a code is valid in the table, before assigning a taxi driver to it.

$sql = "UPDATE cabBookings SET _status = 'assigned' WHERE _booking_code = '$code'";
$sqlTwo = "SELECT * FROM cabBookings WHERE _booking_code = '$code'";

if($result = @mysqli_query($connection, $sqlTwo)){
        if($result->fetchColumn() > 0){
            if (@mysqli_query($connection, $sql)) {
                echo "<p style = 'padding: 10px; background-color: #8ae57b; border: 1px solid black; max-width: 400px;'>Great! Thankyou
                    for taking up your time. You have been assigned the duty of picking up this passenger :-)</p>
                    <button style = 'margin-top: 10px;' type = 'button' onClick = 'location.reload()'>Reload Page</button>";
            } else {
                echo "Error: " . $sql . "<br>" . $connection->error;
            }
        }else{
            echo "<p style = 'padding: 10px; background-color: #ed6c63; border: 1px solid black; max-width: 400px;'>Sorry, the code
                    you have entered is not a current booking</p>";
        }
    }

obviously the code isn't working, and i was just wondering what i am doing wrong

Upvotes: 0

Views: 52

Answers (2)

dhaval
dhaval

Reputation: 190

$result->fetchColumn() is use if you are using PDO library. But here i can see you are using simple mysqli function. so fetchColumn function should not work.

Instead of $result->fetchColumn() use $result->num_rows

Upvotes: 1

Akhilesh B Chandran
Akhilesh B Chandran

Reputation: 6608

You are using @ before the database function names, which will suppress any error messages that it will generate! Details: http://php.net/manual/en/language.operators.errorcontrol.php

Try to do error catching. Maybe catch the error and write to the log file. In this way you will be able to figure out the issues happening in your code! You can check the error_log file to see the errors

And one more thing, I would suggest escaping the table field names and table name in your query using backtick. Example:

$sql = "UPDATE `cabBookings` SET `_status` = 'assigned' WHERE `_booking_code` = '$code'";

Upvotes: 0

Related Questions