简体   繁体   中英

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?

Then, reading the doc you will see that mysql_query return true or false for INSERT query.

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.

$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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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