How to make automatic update data in database in PHP

i want to make toefl test. i make table score_structure in database. that is contain 4 columns (email, right, false, score). so, if a user has done on previous test and will perform a test , then the user data will be updated according to the user’s email pitch .

I have tried but failed, the data will not update. please help me

this is structure.php

<?php
$email = $_SESSION['email'];
              $cek=mysql_num_rows(mysql_query("SELECT email FROM score_structure WHERE email='$email'"));
              if($cek > 0 ){
                $simpan = "UPDATE score_structure SET right='$right', false='$false', score='$score' WHERE email='$email'";
                if(mysql_query($simpan)){
                    header("location:test_listening.php");
                }else {
                      echo mysql_error();
                } 
              else{
                $simpan = "INSERT INTO score_structure VALUES ('$email', '$right', '$false', '$score')";
                if(mysql_query($simpan)){
                    header("location:test_listening.php");
                }else {
                      echo mysql_error();
                }
              }

 ?>

Where are the variables $right, $false and $score coming from? If they’re coming from a form posting, they should be in the form of $_POST['right'] and so on. As you are getting the email address from a session variable, are you sure it is getting the correct value - that is, if you echo $email;, does it show the value you expect?

You also have two column names that are MySQL reserved words - right and false - so you’ll need to enclose those in quotes in any query that uses them, or change them to something else.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.