|
查看: 974|回复: 6
|
请问问题出在哪里?
[复制链接]
|
|
|
<?php
if (isset($_POST["submit"]))
{
$stu_name = $_POST["stu_name"];
$stu_id = $_POST["stu_id"];
//INSERT into [table_name]([colume_name]VALUES ([VALUES])
$sql_status = mysql_query("INSERT INTO student(stu_name,stu_id)VALUES ($stu_name,$stu_id) ");
}
if($sql_status )
{ echo "added sucessfully" ;}
?>
请问有什么问题,当我key in id 和password时,应该会出现added sucessfully,不过却没有出现 == |
|
|
|
|
|
|
|
|
|
|
发表于 10-7-2013 10:08 PM
|
显示全部楼层
- INSERT INTO student(stu_name, stu_id)VALUES ($stu_name, $stu_id)
复制代码 再仔细想想,你的$variable 用对了吗? |
|
|
|
|
|
|
|
|
|
|
发表于 11-7-2013 09:11 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 12-7-2013 10:44 AM
|
显示全部楼层
|
string 就是 string 这是最基本错误,string 就是要 variable with quote |
|
|
|
|
|
|
|
|
|
|
发表于 12-7-2013 12:41 PM
|
显示全部楼层
正解:- $sql_status = mysql_query("INSERT INTO student(stu_name,stu_id)VALUES ('" . $stu_name . "', '" . $stu_id) . "');";
复制代码 $stu_id 和 $stu_name 是PHP variables, 并不是MySQL Parameters,不能那样子用的。 本帖最后由 geekman 于 12-7-2013 07:17 PM 编辑
|
|
|
|
|
|
|
|
|
|
|
发表于 12-7-2013 08:07 PM
|
显示全部楼层
|
正解,除非用mysqli::prepare,才能用parameter。 |
|
|
|
|
|
|
|
|
|
|
发表于 31-7-2013 05:50 PM
|
显示全部楼层
建議把你的Query Statement先存放在 Variable,然後才把Variable 丟進 mysql_query 裡。
這樣的話如果有什麼問題, echo variable 就可以方便檢查你的query是否正確。
|
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|