php - Show message if inserted successfully PDO -
i wrote php code insert records in mysql database. want display message indicating whether records added database or not. tried several times failed.
code:
<?php try { $db_user = 'root'; $db_pass = 'cea123'; $db = new pdo( 'mysql:host=localhost;dbname=symposium', $db_user, $db_pass ); $form = $_post; $sql = "insert app ( firstname, lastname, company, homepage, contactno, addressline1, addressline2, city, postalcode, country, email, abstractdetails ) values ( :firstname, :lastname, :company, :homepage, :contactno, :addressline1, :addressline2, :city, :postalcode, :country, :email, :abstractdetails )"; $query = $db->prepare( $sql ); $query->execute( array( ':firstname'=>$firstname, ':lastname'=>$lastname, ':company'=>$company, ':homepage'=>$homepage, ':contactno'=>$contactno, ':addressline1'=>$addressline1, ':addressline2'=>$addressline2, ':city'=>$city, ':postalcode'=>$postalcode, ':country'=>$country, ':email'=>$email, ':abstractdetails'=>$abstractdetails )); } catch(pdoexception $e) { echo $e->getmessage(); } ?>
you can check using rowcount function,
if($query->rowcount() > 0){ echo "record inserted !!"; }
Comments
Post a Comment