ksmatthews Posted September 21, 2007 Share Posted September 21, 2007 HI THere, I would like to get my php script to send a message to a user for example to notify that a DB update or insert has been successful or not. After that the script will be redirected to the home page. how can this be done ? I have tried using sleep(5) to delay the script but that does not work the way that I want it to since it simply delays the execution of the ENTIRE script RATHER than a part of it !! Any suggestions ? regards, Steven M Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 21, 2007 Share Posted September 21, 2007 simple aproach. was created off the top off my head sorry hope it helps. <?php session_start(); // database connection // users id,name,surname,email are all in a session. // user's posting a comment from a form. $comment="hello redarrow"; $comment=addslashes($_POST['comment']); $id=addslashes($_POST['id']); $name=addslashes($_POST['name']); $email=addslashes($_POST['email']); $date=addslashes($_POST['date']); if(isset($_POST['submit']){ $sql="INSERT INTO what_ever (id,name,surname,email,comment,now()) VALUES('$id','$name','$surname','$comment'")"; $result=mysql_query($sql): if(mysql_affected_rows($result)){ $message1="Thank you $name the database was updated."; $to = $email; $subject = 'database updated from www.what_ever.com'; $message = $message1; $headers = "'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; mail($to, $subject, $message, $headers); echo"thank you $name database updated"; // or use header to redirect somewere else. exit; }else{ $message2=" sorry $name your recent database update on ".date("d-m-y")." was not sent due to database problams."; $to = email; $subject = 'sorry we had a database update problam from www.what_ever.com'; $message = $message2; $headers = "'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; mail($to, $subject, $message, $headers); } echo"Sorry we got a database problam"; // or user header function to redirect user some were elese. exit; } ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 21, 2007 Share Posted September 21, 2007 try using META Tags ie simple message echo '<META http-equiv="refresh" content="5;URL=http://www..phpfreaks.com/"> '; echo "Stuff done."; echo 'You will be redirected to the homepage page automatically in 5 seconds. or click here<a href="http://www..phpfreaks.com/"> http://www..phpfreaks.com/</a>'; Quote Link to comment Share on other sites More sharing options...
hvle Posted September 21, 2007 Share Posted September 21, 2007 why is this a hard problem? you would know right away that a query would be success or failure after attempted. if (successfully queried) send user email else redirect to page Quote Link to comment Share on other sites More sharing options...
ksmatthews Posted September 21, 2007 Author Share Posted September 21, 2007 try using META Tags ie simple message echo '<META http-equiv="refresh" content="5;URL=http://www..phpfreaks.com/"> '; echo "Stuff done."; echo 'You will be redirected to the homepage page automatically in 5 seconds. or click here<a href="http://www..phpfreaks.com/"> http://www..phpfreaks.com/</a>'; I am sorry but I do not see how this would redirect you in 5 seconds. Can you please explain. Thanks, Steven M Quote Link to comment Share on other sites More sharing options...
ksmatthews Posted September 21, 2007 Author Share Posted September 21, 2007 why is this a hard problem? you would know right away that a query would be success or failure after attempted. if (successfully queried) send user email else redirect to page Hi there, I do not want an email (it takes too long), I need a five second message to notify of the success or failure of a DB operation followed by a page redirect ... regards, Steven M Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 21, 2007 Share Posted September 21, 2007 You could show the message on the next page that you redirect to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.