Advertisement
Guest User

Untitled

a guest
May 7th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function add_data(){
  2. if( $_GET["name"] || $_GET["animal"] )
  3. {
  4. $type_animal = $_GET['animal'];
  5. $name_animal = $_GET['name'];
  6. $dsn = 'mysql:host=localhost;dbname=portfolio';
  7. $username = 'root';
  8. $password = '';
  9. $db = new PDO($dsn, $username, $password);
  10. $myquery = 'INSERT INTO animals
  11. ( animal_type, animal_name)
  12. VALUES
  13. ( :type_animal, :name_animal';
  14. $mystatement =$db->prepare($myquery);
  15. $mystatement->bindValue(':type_animal' , $type_animal, PDO::PARAM_STR);
  16. $mystatement->bindValue(':type_animal' , $name_animal, PDO::PARAM_STR);
  17. $sucess = $mystatement->execute();
  18. $row_count = $mystatement->rowCount();
  19. $mystatement-> closeCursor();
  20. $animal = $db->lastInsertID();
  21. if ($sucess) {
  22. echo "<p>$row_count row was inserter with this ID: $animal</p> ";
  23. }else{
  24. echo "no records add" . "<br />";
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement