Hi Could somebody help please? I have a mysql table. When I update a column I want the past entry to be posted to the next column. The table collects quiz scores, so when the user gets a new score I want the old score to be placed into the ‘pastscore’ column. I’m pretty new to php and mysql, so could you possibly show me the language. I’ve been trying for hours. Cheers
how about adding a new record for each text taken by the user including the datetime. You will then have a archived record of all the tests they have take. This would work too: UPDATE test SET pastscore=score ,score='newscore' WHERE .....
Thanks I'll try it now and get back to you asap. I'm just on my way out at the moment. it maybe tomorrow now. Many thanks in advance
Hi I’m having this problem. Here is my table: username quizid score date pastscore pastdate I want my quiz to work like this. After the student takes the quiz for a second time, the score is updated, and the previous score and date are moved to ‘pastscore’ and ‘pastdate’ respectively. Below is the whole code I am using, but it posts ‘score’ and ‘date’ into the database fields when I run the file. I can’t get it to ‘capture’ the actual scores and dates. ServerUnion, thanks for your help, but I couldn’t get your recommendation to work. Any ideas? <?php $username=$_REQUEST["username"]; $quizid=$_REQUEST["quizid"]; $score=$_REQUEST["score"]; $dates=$_REQUEST["dates"]; $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("scores", $con); mysql_query("UPDATE scoredate SET score = '$score' WHERE username = 'name' AND quizid = 't4'"); mysql_query("UPDATE scoredate SET date = '$dates' WHERE username = 'name' AND quizid = 't4'"); mysql_query("UPDATE scoredate SET pscore = 'score' WHERE username = 'name' AND quizid = 't4'"); mysql_query("UPDATE scoredate SET pdate = 'date' WHERE username = 'name' AND quizid = 't4'"); mysql_close($con); ?>
Try something like this, don't do much PHP,but you get the jist of it. mysql_query("UPDATE scoredate SET pscore = score, pdate=date,score = '$score', date = '$dates' WHERE username = 'name' AND quizid = 't4'"); Code (markup):
Hi ServerU It’s getting closer, but now when I score the quiz, the new score and date is getting put into both the new score and date, ‘and’ the past score and date. I can’t see how this is happening.
mysql_query("UPDATE scoredate SET pscore = score, pdate=date WHERE username = 'name' AND quizid = 't4'"); mysql_query("UPDATE scoredate SET score = '$score', date = '$dates' WHERE username = 'name' AND quizid = 't4'"); Code (markup):
Hi ServerU Sorry, now the code is just updating the score and date and the pscore and pdate are empty.
ServerU Is this correct? When the student does the quiz the first time, the score and date are stored in the ‘score’ and ‘date’ respectively. This is happening. When the student does the quiz again, the values of the ‘score’ and ‘date’ are captured and moved to the ‘pscore’ and ‘pdate’. This happens. From what I know (very little), the code you have given me ‘should’ capture the values of the ‘score’ and ‘date’. I think your code is correct, but this isn’t happening. Is this correct?
If I run the following code on its own, it updates the score and date perfectly. However, I want this to run as the student completes the quiz a second time. There appears to be a problem when I try to load the ‘new’ score in the same code. <?php $username=$_REQUEST["username"]; $quizide=$_REQUEST["quizid"]; $con = mysql_connect("localhost","name","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("scores", $con); mysql_query("UPDATE scoredate SET pscore = score, pdate = date WHERE username = 'name' AND quizid = 't4'"); mysql_close($con); ?>