0

I want to make toefl test. I make table score_structure in database containing 4 columns (email, right, false, score). If the user has done on previous test and will perform a test again, 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(); 
    } 
  }

 ?>
Fil
  • 8,225
  • 14
  • 59
  • 85
cassie
  • 13
  • 4
  • 3
    Try to use `mysqli` or `PDO` – ASR Jun 02 '16 at 02:56
  • don't post the same question 2 times - http://stackoverflow.com/questions/37580925/how-to-take-data-from-2-tables-in-database-and-count-it-in-php - if you are not getting answers consider adding additional info to your original question – Sean Jun 02 '16 at 03:03
  • Using mysql_* functions are now deprecated and will return E_DEPRECATED when executed. Use MySQLi_* functions instead or PDO. – GROVER. Jun 02 '16 at 03:04
  • You could simplify this with MySQL's [INSERT ... ON DUPLICATE KEY UPDATE Syntax](http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html) – Sean Jun 02 '16 at 03:14
  • You have written code that is vulnerable to [SQL Injection](http://stackoverflow.com/questions/601300/what-is-sql-injection). – rrauenza Jun 02 '16 at 04:11

1 Answers1

0

Update your update query & let us know the feedback:

$simpan = "UPDATE score_structure SET `right`='$right', `false`='$false', `score`='$score' WHERE email='$email'";

Also currently mysql_() are depreciated so use mysqli_()

Dipanwita Kundu
  • 1,637
  • 1
  • 9
  • 14