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);
4

5 回答 5

6

首先你应该阅读这个帖子:为什么我不应该在 PHP 中使用 mysql_* 函数?

然后,阅读文档,您将看到mysql_queryINSERT 查询返回 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();
}
于 2012-11-07T08:37:09.390 回答
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';
}
于 2012-11-07T08:36:03.813 回答
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 .
于 2014-01-27T11:21:51.850 回答
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>";
于 2012-11-07T08:36:58.457 回答
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";
}
于 2012-11-07T08:37:58.613 回答