...

View Full Version : Need help to get the Alert message after redirect



nani_nisha06
10-12-2012, 09:30 PM
Hi frnds,

As per my subject line I need to change the below code.

1) Actually I want to write a time deference to be automatically calculated between Report_Date, Resolved_Date & updated in the SLA column. can you please help me with this calculation.
a) If resolved_date is not selected in the form then the value of the SLA can be Null, One resolved_date is updated it should automatically update time difference In SLA. also time should be in format (hhh:mm:ss).

2) on inserting a record it should first redirect to the page mentioned and then alert the message saying "record inserted successfully"


<?php
session_start();
$host="localhost"; // Host name
$username="test"; // Mysql username
$password="1234"; // Mysql password
$db_name="testapp"; // Database name
$tbl_name="user_supp"; // Table name
$myusername = $_SESSION['myusername']; //user who updating
$con = mysql_connect("$host","$username","$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name( `prefix`,`Analyst`, `Email`, `Report_Date`, `Resolved_Date`, `Issue_des`, `Resolution_des`, `SLA`)

VALUES

('SUPP_MYM_','$myusername','$_POST[requiredEmail]','$_POST[requiredRD]','$_POST[ResD]','$_POST[IssueNotes]','$_POST[RNotes]','$_POST[SLA]')";

$result1=mysql_query($sql)or die(mysql_error());
{

header("location:support_update.php") or die("record not inserted");
}
echo '<script language="javascript">';
echo 'alert("you have successfully added one user !" );';
echo ' window.location="support.php";';
echo '</script>';
mysql_close();
?>

Any help appreciated.

regards,
nani

Fou-Lu
10-12-2012, 09:35 PM
Impossible. The location header is handled by the client which then ignores the body. You cannot have an alert if you are using a location. An unofficial header of Refresh: 5; url=http://site.com/page would allow you to do this as it will wait 5 seconds before it redirects. Meta headers could also be used for a similar effect. Refresh header is not a part of RFC-2616 standards though, so there is no guarantee that it will work.

Redcoder
10-17-2012, 05:08 PM
The below slightly modified code will enable you to echo the contents first then redirect after 5 seconds.

Your code refreshed before even echoing the HTML and Javascript to the client.




<?php
session_start();
$host="localhost"; // Host name
$username="test"; // Mysql username
$password="1234"; // Mysql password
$db_name="testapp"; // Database name
$tbl_name="user_supp"; // Table name
$myusername = $_SESSION['myusername']; //user who updating
$con = mysql_connect("$host","$username","$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name( `prefix`,`Analyst`, `Email`, `Report_Date`, `Resolved_Date`, `Issue_des`, `Resolution_des`, `SLA`)

VALUES

('SUPP_MYM_','$myusername','$_POST[requiredEmail]','$_POST[requiredRD]','$_POST[ResD]','$_POST[IssueNotes]','$_POST[RNotes]','$_POST[SLA]')";

$result1=mysql_query($sql)or die(mysql_error());

echo '<script language="javascript">';
echo 'alert("you have successfully added one user !" );';
echo ' window.location="support.php";';
echo '</script>';
mysql_close();

header('refresh: url=5; support_update.php'); //Refresh after 5 seconds
?>

nani_nisha06
10-25-2012, 12:25 PM
The below slightly modified code will enable you to echo the contents first then redirect after 5 seconds.

Your code refreshed before even echoing the HTML and Javascript to the client.




<?php
session_start();
$host="localhost"; // Host name
$username="test"; // Mysql username
$password="1234"; // Mysql password
$db_name="testapp"; // Database name
$tbl_name="user_supp"; // Table name
$myusername = $_SESSION['myusername']; //user who updating
$con = mysql_connect("$host","$username","$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name( `prefix`,`Analyst`, `Email`, `Report_Date`, `Resolved_Date`, `Issue_des`, `Resolution_des`, `SLA`)

VALUES

('SUPP_MYM_','$myusername','$_POST[requiredEmail]','$_POST[requiredRD]','$_POST[ResD]','$_POST[IssueNotes]','$_POST[RNotes]','$_POST[SLA]')";

$result1=mysql_query($sql)or die(mysql_error());

echo '<script language="javascript">';
echo 'alert("you have successfully added one user !" );';
echo ' window.location="support.php";';
echo '</script>';
mysql_close();

header('refresh: url=5; support_update.php'); //Refresh after 5 seconds
?>



Redcoder,

This is not working for me I have checked with multiple formate still have same issue...

While triggering alert it is showing blank page back end. also, if any notices or errors while running the PhP code it is clearly visible.

Now, I want to avoid such visibility to the user ..pls suggest me best way....

FYR... attached SS.

Redcoder
10-25-2012, 01:31 PM
That probably means that you have included another file in the above php file which also has a `session_start()` in it.

nani_nisha06
10-25-2012, 01:54 PM
That probably means that you have included another file in the above php file which also has a `session_start()` in it.

Redcoder,

I have already cleared the issue of the error but I am more concern about the blank page while alerting.....after clearing the error as well i am seeing blank page till I click OK on the alert....

Any chance first i redirect to desire page and then alert the message ?

or any other procedure of the same......

Redcoder
10-25-2012, 02:00 PM
Then if you don't want to see the alert, clear these Javascript lines:



echo '<script language="javascript">';
echo 'alert("you have successfully added one user !" );';
echo ' window.location="support.php";';
echo '</script>';

The above lines mean that essentially you have two lines of code to redirect the page. The window.location and the header();

Put something simple like this message to show that the update was successful.




echo 'You have successfully added one user';



After echoing that, the browser will refresh after 5 seconds.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum