简体   繁体   English

打印成功保存在Php中的代码

[英]Print Successfully Saved Code in Php

I am using below code, how do i do the message as saved successfully, after submitting all the values in database. 我正在使用下面的代码,提交数据库中的所有值后,如何成功保存消息?

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

First you should read this thread: Why shouldn't I use mysql_* function in PHP? 首先,您应该阅读以下主题: 为什么我不应该在PHP中使用mysql_ *函数?

Then, reading the doc you will see that mysql_query return true or false for INSERT query. 然后, 阅读文档,您将看到mysql_query对于INSERT查询返回true或false。

So: 所以:

$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();
}
$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';
}

Use the die to stop the script else display saved successfully. 使用模具停止脚本,否则显示保存成功。

$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>";

Anything within the if statement will be processed if the entry into the database is a success. 如果成功进入数据库,则将处理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";
}
$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 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM