Viewed   467 times

I am trying to update the table but nothing is changing. The database name and fields are correct.

    $forname  = $_POST['name'];
    $newval = "yes";
    mysqli_query($con, "UPDATE pupils SET signin = '$newval' WHERE forname = '$forname'");

Help appreciated! Thanks,


Appears that data is not posting correctly for some reason.

<form class="form-inline" name="markin" role="form" method="POST" action="markin.php">
    <div class="form-group">
    <select class="form-control" name"name" id="name">
    $query = "SELECT * FROM `pupils` WHERE signin = 'no'";//Grab the data
    $result = mysqli_query($con, $query);
    while ($row = mysqli_fetch_array($result)) {//Creates a loop to loop through results
    echo "<option>" . $row['forname'] . "</option>";//$row['index'] the index here is a field name
    <button type="submit" class="btn btn-success">Mark in</button>



First, I suggest you read the prepared statements quickstart guide which would lead you to something like this...

$stmt = $con->prepare('UPDATE pupils SET signin = ? WHERE forname = ?');
$stmt->bind_param('ss', $newval, $forname);

As an added bonus, you should set mysqli to throw exceptions on error so you don't have to check return values all the time. In your config.php file, before creating the connection, do this...

$con = new mysqli(...); // or however you create $con

and as mentioned in the comments, the php.ini file in your development environment should enable full error reporting with the following directives

error_reporting = E_ALL
display_errors = On

To directly answer your question, you're missing an equals sign for the <select> elements name attribute. It should be

<select class="form-control" name="name" id="name">
Wednesday, August 24, 2022

The answer is I was forgetting to call mysqlistmt::store_result after mysqlistmt::execute().

Once I added $dupSelectStmt->store_result(); I was able to call $dupSelectStmt->num_rows and $portableDB->affected_rows and they both showed the 24 I knew I should be seeing.

Wednesday, September 7, 2022

Looking Back on this question now a year later I can see exactly what i did wrong. in the form i didn't give it any action, i left it at <form action="" method="post">. It should have been <form action="#" method="post">. basic stuff up by a beginner.

Monday, December 19, 2022

What I typically do is something like this.

Also, you need to make sure you have a field or something that is unique to this record. Basically, it will always INSERT the way it's written, since we're just checking one value (birthday)

Here's an example

$conn = new mysqli('localhost', 'username', 'pwd', 'db');

    // check connection
    if (mysqli_connect_errno()) {
      exit('Connect failed: '. mysqli_connect_error());
            // check to see if the value you are entering is already there      
            $result = $conn->query("SELECT * FROM birthday WHERE name='Joe'");
            if ($result->num_rows > 0){ 
                // this person already has a b-day saved, update it
                $conn->query("UPDATE birthday SET birthday = '$birthday' WHERE name = 'Joe'");
                // this person is not in the DB, create a new ecord
                $conn->query("INSERT INTO `birthday` (`birthday`,`name`) VALUES ('$birthday','Joe')");
Wednesday, September 14, 2022

Did you set the exception mode for PDO with:


Update: check is mysql reserved words, you need to escape it.

$STH = $DBH->prepare('UPDATE accounts SET `check` = :check_amnt WHERE accnt = :user');
Monday, October 3, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :