您使用的方法是正确的,但语法错误:
<?php
$marks+=$_POST['$cqid']; //Not Correct!
//1st You haven't defined $cqid. Its $qid.
//2nd You can't use a variable inside single quotes.
//PHP will consider it as normal String. But you can use it inside double quotes.
//But remember you can't use array ($row['cqid']) inside double quotes.
?>
这是正确的方法:
<?php
while ($row = mysql_fetch_array($result)) {
//$qid=$row['cqid'];
//$marks+=$_POST[$qid]; //Correct!
//But, Not needed You can directly use $row['cqid'] as an index.
$marks+=$_POST[$row['cqid']];
}
?>
更新:[用于调试]
while ($row = mysql_fetch_array($result)) {
$marks+=$_POST[$row['cqid']];
echo $marks.'<br/>';
}
$insert="insert into result(email,marks)values('$email',$marks)";
$insert = mysql_query($insert);
if(!$result) {
die('Unable to perform insert action. The following error occured: '. mysql_error());
} else {
echo 'The following Query: <b>'.$insert.'</b> executed successfully!';
}
还要检查$email
我看不到从哪里获得该值的值。
并且$login_session = $_POST['email'];
此行重复了两次,但我确信此值始终为空,因为在test.php中您已注释了以下行:
echo "<input type='hidden' name='email' value='email' />";
value 属性:value='email'
显然好像不对!
检查所有这些东西,我想你现在可以从这里继续...... :) 如果没有,我仍然很乐意帮助你......
更新:[用于在查询中设置限制]
SELECT * FROM `cquestions` LIMIT 0,3;
//Will fetch first three records from cquestions.
SELECT * FROM `cquestions` LIMIT 2,3;
//Will fetch 3rd, 4th and 5th records from cquestions.