我正在使用下面的代码,在提交数据库中的所有值后,如何成功保存消息。
$query = "INSERT INTO applyonline (name, email, gender, phone, dob, applicationintake, applicationintake2, degree, ielts, experience, experience2) VALUES ('".$name."', '".$email."','".$gender."','".$phone."','".$dob."','".$applicationintake1."','".$applicationintake2."','".$degree."','".$ielts."','".$experience1."','".$experience2."')";
$result = mysql_query($query);
答案 0 :(得分:6)
首先你应该阅读这个主题:Why shouldn't I use mysql_* function in PHP?
然后,reading the doc您将看到mysql_query
对INSERT查询返回true或false。
所以:
$query = "INSERT INTO applyonline (name, email, gender, phone, dob, applicationintake, applicationintake2, degree, ielts, experience, experience2) VALUES ('".$name."', '".$email."','".$gender."','".$phone."','".$dob."','".$applicationintake1."','".$applicationintake2."','".$degree."','".$ielts."','".$experience1."','".$experience2."')";
$result = mysql_query($query);
if (true === $result)
{
echo 'All right !';
}
else
{
echo 'Something is wrong: ' . mysql_error();
}
答案 1 :(得分:1)
$query = "INSERT INTO applyonline (name, email, gender, phone, dob, applicationintake, applicationintake2, degree, ielts, experience, experience2) VALUES ('".$name."', '".$email."','".$gender."','".$phone."','".$dob."','".$applicationintake1."','".$applicationintake2."','".$degree."','".$ielts."','".$experience1."','".$experience2."')";
$result = mysql_query($query) or die('error while saving data');
if($result){
echo 'data saved successfully';
}
答案 2 :(得分:0)
使用骰子停止脚本,否则显示已成功保存。
$query = "INSERT INTO applyonline (name, email, gender, phone, dob, applicationintake, applicationintake2, degree, ielts, experience, experience2) VALUES ('".$name."', '".$email."','".$gender."','".$phone."','".$dob."','".$applicationintake1."','".$applicationintake2."','".$degree."','".$ielts."','".$experience1."','".$experience2."')";
$result = mysql_query($query) or die("Could not save");
if ($result)
echo "<br>Saved</br>";
答案 3 :(得分:0)
如果输入数据库成功,将处理if语句中的任何内容。
$query = "INSERT INTO applyonline (name, email, gender, phone, dob, applicationintake, applicationintake2, degree, ielts, experience, experience2) VALUES ('".$name."', '".$email."','".$gender."','".$phone."','".$dob."','".$applicationintake1."','".$applicationintake2."','".$degree."','".$ielts."','".$experience1."','".$experience2."')";
$result = mysql_query($query);
if($result){
echo "Data has been saved";
}
答案 4 :(得分:0)
$query = "INSERT INTO applyonline (name, email, gender, phone, dob, applicationintake, applicationintake2, degree, ielts, experience, experience2) VALUES ('".$name."', '".$email."','".$gender."','".$phone."','".$dob."','".$applicationintake1."','".$applicationintake2."','".$degree."','".$ielts."','".$experience1."','".$experience2."')";
$result = mysql_query($query) or die(mysql_error());
if($result){
echo 'data saved successfully';
}
mysql_error() function will explain you error in detail .