1

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);
j0k
  • 22,600
  • 28
  • 79
  • 90
Nikita Chopra
  • 119
  • 1
  • 6
  • 15

5 Answers5

6

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();
}
Community
  • 1
  • 1
j0k
  • 22,600
  • 28
  • 79
  • 90
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';
}
Pragnesh Chauhan
  • 8,363
  • 9
  • 42
  • 53
0

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>";
Romaan
  • 2,645
  • 5
  • 32
  • 63
0

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";
}
George
  • 36,413
  • 9
  • 66
  • 103
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 .