如何在PHP中自动更新数据库中的数据 [英] How to automatic update data in database in PHP
本文介绍了如何在PHP中自动更新数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想进行托福考试.我在包含4列(电子邮件,正确,错误,得分)的数据库中制作了表score_structure.如果用户已经完成了先前的测试并且将再次执行测试,则将根据用户的电子邮件提示更新用户数据.
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.
这是structure.php
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();
}
}
?>
推荐答案
更新您的更新查询&让我们知道反馈:
Update your update query & let us know the feedback:
$simpan = "UPDATE score_structure SET `right`='$right', `false`='$false', `score`='$score' WHERE email='$email'";
目前还折旧了mysql_ (),因此请使用mysqli _ ()
Also currently mysql_() are depreciated so use mysqli_()
这篇关于如何在PHP中自动更新数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文