PHP MySQL Insert Record
From w3cyberlearnings
Contents |
PHP MySQL INSERT Records
Insert a new record using the INSERT Statement.
Syntax
$insert_query = ' INSERT INTO student (first_name, last_name) VALUES ("Johny","Zhar"), ("Jacob","Milli"), ("Isabella","Catous"), ("Michael","Vieva"), ("Emma","lee") '; mysql_query($insert_query, $connection);
Example 1
<?php define('HOST', 'localhost'); define('USER', 'root'); define('PASS', 'yeething'); define('DBNAME', 'woowood'); $connection = mysql_connect(HOST, USER, PASS); if (!$connection) { die("can not connect to the server!<br/>"); } else { $rdb = mysql_select_db(DBNAME); if (!$rdb) { die("The " . DBNAME . "database could not be selected"); } else { // insert to the student table query $insert_query = ' INSERT INTO student (first_name, last_name) VALUES ("Johny","Zhar"), ("Jacob","Milli"), ("Isabella","Catous"), ("Michael","Vieva"), ("Emma","lee") '; // insert to student table if (!mysql_query($insert_query, $connection)) { echo "Can't insert student record : " . mysql_error($connection); } else { echo "You have successfully insert records into student table"; } } } mysql_close($connection); ?>
Output
You have successfully insert records into student table