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();
?>

--------

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();

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.