Jump to content

Archived

This topic is now archived and is closed to further replies.

karl_009

[SOLVED] Popup Message after form submitted

Recommended Posts

Hello,

 

I have this code and it displays messages after the form is submitted, how I would go about redirecting this to another page and a popup message saying successful.

 

I believe it will be the IF statement at the end that I will need to update?

 

Here is the code that I am using now;

 

<?php
require ($_SERVER['DOCUMENT_ROOT']."cmstesting/config/db_config.php");
$connection = mysql_connect ($db_host, $db_user, $db_pass) or die ("Error with Connection");
mysql_select_db ($db_name, $connection);

	$conid = $_POST["conid"];
	$submitted = $_POST["submitted"];

$query = "UPDATE contacts SET title='{$_POST["title"]}', first='{$_POST["first"]}', last='{$_POST["last"]}', suffix='{$_POST["suffix"]}', company='{$_POST["company"]}', address1='{$_POST["address1"]}', address2='{$_POST["address2"]}', city='{$_POST["city"]}', town='{$_POST["town"]}', country='{$_POST["country"]}', postcode='{$_POST["postcode"]}', website='{$_POST["website"]}', email='{$_POST["email"]}', hp1='{$_POST["hp1"]}', hp2='{$_POST["hp2"]}', hp3='{$_POST["hp3"]}', mp1='{$_POST["mp1"]}', mp2='{$_POST["mp2"]}', mp3='{$_POST["mp3"]}', notes='{$_POST["notes"]}' WHERE conid='$conid'";

	$result = mysql_query($query);

if ($result)
{
echo "Successful";
echo "<BR>";
echo "<a href='contact_view.php'>View</a>";
}
else
{
echo "ERROR";
}

?>

 

Thanks

Karl

Share this post


Link to post
Share on other sites

 

 

 

if ($result)
   {
   header("Location: http://$host$uri/contact_view.php");
   }

 

 

Because you're using header function, you need to have this at the top of your script,

you cannot output anything before the header function....

Share this post


Link to post
Share on other sites

Thanks for that, the page now redirects to the page...

 

Is there away to have a popup message popup, then continue on to the page...

 

<?php
if ($result)
{
//	echo "Successful";
//	echo "<BR>";
//	echo "<a href='contact_view.php'>View</a>";

echo "<script type='text/javascript'>alert('Successful')</script>";
header("Location: http://localhost/cmstesting/contact_view.php");
}
else
{
echo "ERROR";
}

?>

 

 

I have included;

echo "<script type='text/javascript'>alert('Successful')</script>";

 

Is there away to execute this code then the header code after this has been OK...

 

Many Thanks

Karl

 

Share this post


Link to post
Share on other sites

Thanks for that, the page now redirects to the page...

 

Is there away to have a popup message popup, then continue on to the page...

 

<?php
if ($result)
{
//	echo "Successful";
//	echo "<BR>";
//	echo "<a href='contact_view.php'>View</a>";

echo "<script type='text/javascript'>alert('Successful')</script>";
header("Location: http://localhost/cmstesting/contact_view.php");
}
else
{
echo "ERROR";
}

?>

 

 

I have included;

echo "<script type='text/javascript'>alert('Successful')</script>";

 

Is there away to execute this code then the header code after this has been OK...

 

Many Thanks

Karl

 

 

No, what you should do is load that script on the new page on the top...this way right

before the new page loads, you load the pop up...

 

 

Share this post


Link to post
Share on other sites

I found a solution, it did not use PHP but I thought I would post it anyway.

 

<?php
if ($result)
{
// Successful popup message, redirected back to view contacts
echo "<script type='text/javascript'>alert('Successful - Record Updated!'); window.location.href = 'contact_view.php';</script>";
}
else
{
// Unsuccessful popup message, redirected back to view contacts
echo "<script type='text/javascript'>alert('Unsuccessful - ERROR!'); window.location.href = 'contact_view.php';</script>";
}
?>

 

Thanks for the replies

Karl

Share this post


Link to post
Share on other sites

I found a solution, it did not use PHP but I thought I would post it anyway.

 

<?php
if ($result)
{
// Successful popup message, redirected back to view contacts
echo "<script type='text/javascript'>alert('Successful - Record Updated!'); window.location.href = 'contact_view.php';</script>";
}
else
{
// Unsuccessful popup message, redirected back to view contacts
echo "<script type='text/javascript'>alert('Unsuccessful - ERROR!'); window.location.href = 'contact_view.php';</script>";
}
?>

 

Thanks for the replies

Karl

 

Good script, I will save that script myself for future purposes...

 

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.