Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_data(){
- if( $_GET["name"] || $_GET["animal"] )
- {
- $type_animal = $_GET['animal'];
- $name_animal = $_GET['name'];
- $dsn = 'mysql:host=localhost;dbname=portfolio';
- $username = 'root';
- $password = '';
- $db = new PDO($dsn, $username, $password);
- $myquery = 'INSERT INTO animals
- ( animal_type, animal_name)
- VALUES
- ( :type_animal, :name_animal';
- $mystatement =$db->prepare($myquery);
- $mystatement->bindValue(':type_animal' , $type_animal, PDO::PARAM_STR);
- $mystatement->bindValue(':type_animal' , $name_animal, PDO::PARAM_STR);
- $sucess = $mystatement->execute();
- $row_count = $mystatement->rowCount();
- $mystatement-> closeCursor();
- $animal = $db->lastInsertID();
- if ($sucess) {
- echo "<p>$row_count row was inserter with this ID: $animal</p> ";
- }else{
- echo "no records add" . "<br />";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement