insert语句中的where子句

时间:2014-09-23 10:07:59

标签: php mysql

大家好,我有两个表测试和问题。每个测试都有很多问题,并且有很多测试。我想做的是动态重定向用户创建问题,就像我们为更新所做的更新一样。

此代码用于插入

if(isset($_REQUEST['add'])){
$insert=$connection->query(
"INSERT INTO questions
(question,ans1,ans2,ans3,ans4,correct_answ,marks,related_to_test)
VALUES
('$question','$ans1','$ans2','$ans3','$ans4','$correct_answ','$marks','$related_to_test')
where related_to_test='".$_REQUEST['add']."'");
//None of them is working
set related_to_test='".$_REQUEST['add']."'");
}

此代码将用户从测试页面重定向以创建问题

<a class="btn btn-info" href="questions.php?add=<?php echo $result['test_id']; ?>">
<i class="icon-edit icon-white"></i>  
Add Question                                            
</a>

上面的代码插入记录但除了related_to_test或页面重定向到的所有字段都闪烁。

非常感谢任何帮助

2 个答案:

答案 0 :(得分:0)

除非是INSERT,否则您无法WHERE clause WHERE NOT EXISTS,所以只需执行:

INSERT INTO components(Quantity) VALUES(x)

答案 1 :(得分:0)

使用此

INSERT INTO questions(question,ans1,ans2,ans3,ans4,correct_answ,marks,related_to_test)
VALUES
('$question','$ans1','$ans2','$ans3','$ans4','$correct_answ','$marks','$related_to_test');

一些注释:: 使用它,因为它应该可以正常工作,因为你可以使用插入中的claues。但仍然可以在where子句中查看查询中的列名 related_to_test ,其值为 $ related_to_test ,因此在我看来它会在正确的位置插入值。希望我能正确解释。

相关问题