Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/70149-php-messaging-and-sleep/
Share on other sites

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;
}
?>

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>';

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.