Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-12-2012, 08:30 PM   PM User | #1
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
Exclamation Need help to get the Alert message after redirect

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 Code:
 <?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
nani_nisha06 is offline   Reply With Quote
Old 10-12-2012, 08:35 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-17-2012, 04:08 PM   PM User | #3
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
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 Code:

<?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
?>
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 10-25-2012, 11:25 AM   PM User | #4
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
Quote:
Originally Posted by Redcoder View Post
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 Code:

<?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.
Attached Thumbnails
Click image for larger version

Name:	error.jpg
Views:	10
Size:	46.5 KB
ID:	11649  
nani_nisha06 is offline   Reply With Quote
Old 10-25-2012, 12:31 PM   PM User | #5
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
That probably means that you have included another file in the above php file which also has a `session_start()` in it.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 10-25-2012, 12:54 PM   PM User | #6
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
Quote:
Originally Posted by Redcoder View Post
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......

Last edited by nani_nisha06; 10-25-2012 at 12:58 PM..
nani_nisha06 is offline   Reply With Quote
Old 10-25-2012, 01:00 PM   PM User | #7
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Then if you don't want to see the alert, clear these Javascript lines:

PHP Code:
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.

PHP Code:

echo 'You have successfully added one user'
After echoing that, the browser will refresh after 5 seconds.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk

Last edited by Redcoder; 10-25-2012 at 01:11 PM..
Redcoder is offline   Reply With Quote
Users who have thanked Redcoder for this post:
nani_nisha06 (10-25-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.