0

Hi,

Below code Insert fine but after insert, i like to see a message "insert passed" or "insert failed" if failed. I think i need to have if else statement. not sure how to do that. thanks.
---------
<?

mysql_connect("host",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO new VALUES ('$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

mysql_close();
?>

--------

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by charlybones
0

Just use the mysql_affected_rows function.

mysql_connect('host', $username, $password);
@mysql_select_db($database) or die('Unable to select database');

$query = "INSERT INTO new VALUES ('$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

if(1 === mysql_affected_rows())
    echo 'insert passed';
else
    echo 'insert failed';

mysql_close();
0

Thanks. It works.

Another question: After "insert passed", i like to receive an automatic email with all values($first, $last, ....).

that means user fill up the form n submit. I get an email with all the info.

Thanks.

0
mysql_connect('host', $username, $password);
    @mysql_select_db($database) or die('Unable to select database');
     
    $query = "INSERT INTO new VALUES ('$first','$last','$phone','$mobile','$fax','$email','$web')";
    mysql_query($query);
     
    if(1 === mysql_affected_rows()){
        echo 'insert passed';
        $to = "recipient@example.com";
        $subject = "Hi!";
        $body = "Your data was inserted into the DB correctly!";
        if (mail($to, $subject, $body)) {
           echo("<p>Message successfully sent!</p>");
        } else {
        echo("<p>Message delivery failed...</p>");
        }
    }
    else
    echo 'insert failed';
    mysql_close();

More on e-mails.
http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm
http://es2.php.net/manual/en/book.mail.php

Edited by charlybones: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.