hi,

I am doing a insert query over here and if the query is executed successfully, there will be a success message. However, whenever the query is being executed successfully, the success message is not being displayed.

here is a snipet, can anybody guide me along? thanks alot.

//Execute SQL Statement and store results as a recordset
  $result= mysql_query($sql) or die (mysql_error());

if ( $result != ""  )
  { 
	echo "Contact successfully added.";
  }
  else
   {
echo "Please try again."; 
   }

Hi!

When executing a query which alters the table (UPDATE, INSERT, etc...), mysql_query returns TRUE on success and FALSE on error.

So your if-clause should read

if ($result == TRUE) {

or simply

if ($result) {

Hope that helps!

Happy coding! :)

Hi!

When executing a query which alters the table (UPDATE, INSERT, etc...), mysql_query returns TRUE on success and FALSE on error.

So your if-clause should read

if ($result == TRUE) {

or simply

if ($result) {

Hope that helps!

Happy coding! :)

hey,

I've tried your method, but it is still not working and the success message is being displayed whenever it loads for the first time. Any idea why is this happening?

Regards,
heels

This should be your code.

$result = mysql_query($sql);

if ( $result )
{ 
  echo "Contact successfully added.";
}
else
{
  echo mysql_error(); 
}

If this does not work, their may be something wrong in your sql statement.

This should be your code.

$result = mysql_query($sql);

if ( $result )
{ 
  echo "Contact successfully added.";
}
else
{
  echo mysql_error(); 
}

If this does not work, their may be something wrong in your sql statement.

ah, thanks alot. :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.