Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    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
    ?>

  • #4
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    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 Attached Thumbnails Need help to get the Alert message after redirect-error.jpg  

  • #5
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    That probably means that you have included another file in the above php file which also has a `session_start()` in it.

  • #6
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    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.

  • #7
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    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.
    Last edited by Redcoder; 10-25-2012 at 01:11 PM.

  • Users who have thanked Redcoder for this post:

    nani_nisha06 (10-25-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •