1

Good day. I want to insert value into my tblEvaluation.

This is my code *HTML*

<form  method="POST" action="<?php $_PHP_SELF ?>">
            <?php

        $query = "select * from tblEvaluation";
        $request = mysql_query($query)or die(mysql_error());?>
        <h3>Evaluation</h3>
        <table class="table table-hover" style="width:auto;">
        <?php
        $i = 1;
        while ($row = mysql_fetch_array($request)) {

            ?>
        <tr>
        <td style="width:20px;"><?php echo $i; ?></td>
        <td><textarea class="form-control" name="question[]" readonly style="width:250px;"><?php echo $row['Question']; ?></textarea></td>
        <input type="hidden" value="<?php echo $row['id']; ?>" name="id[]">
        <td><select class="form-control" name="answer[]">
        <option>Excellent</option>
        <option>Very Good</option>
        <option>Good</option>
        <option>Need Improvement</option>
        <option>Poor</option>
        </select></td></tr>
        <?php
        $i++;
    }
    ?>
        </table>
        <div style="float:right;"> 
        <input type="submit" class="btn btn-success" name="evaluate" value="Evaluate">
        <input type="button" value="Back" class="btn btn-danger" name="Back" onclick="window.location.href='client-home.php'">
         </div>
        </div>
        </div>
        </form>

PHP

if (isset($_POST['evaluate'])) {
$count = count($_POST['answer']); //get total number of array element
for ($i = 0; $i < $count; $i++) { // loop through array and assign values in variable and insert itin database
    $answer = $_POST['answer'][$i];
    $id   = $_POST["id"][$i];
        $sql = "Insert into tblEvaluation (Answer) VALUES ('$answer') Where id = '$id'";
        $success = mysql_query($sql) or die (mysql_error());
        if ($success == TRUE) {
            ?>
            <script>
                alert('You have successfully update account.');
            window.location.href='client-home.php';
            </script>

        <?php
        }
         else {
            ?>
            <script>
                alert('Error.');
            </script>

        <?php
        }

}

} This is the error that im getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Where id = '17'' at line 1

I guess it's on the loop but i don't know what to do. Thanks for any help.

4

1 Answer 1

4

There is no where clause in Insert Query. You can use Update query instead (is data already exixts); e.g

Update table set column='value' where id='yourid';
Sign up to request clarification or add additional context in comments.

2 Comments

This is my query ( $sql = "Insert into tblEvaluation (Answer) VALUES ('$answer') Where id = '$id'";)
use $sql = update tblEvaluation set Answer='$answer' where id='$id'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.