PHP SQL Insert Statement show you the message when the records are inserted successfully into table "stu''.
Understand with Example
The Tutorial illustrate an example from 'PHP SQL Insert Statement'. To understand and illustrate an example 'PHP SQL Insert Statement', we create a table 'stu' with required fieldnames and datatypes respectively. The Table 'stu' has a Primary Key id.
Create Table Stu:
CREATE TABLE `stu` ( `id` int(11) NOT NULL auto_increment, `name` varbinary(10) default NULL, `class` int(11) default '12', PRIMARY KEY (`id`) )
The PHP scripting code begins with <?php and end with ?>. The scripting code include the scripting components that are required for PHP to connect the Mysql database. Once your connection is built, it is possible to insert the records from PHP to your table in database.
<?php $host = "localhost"; $user = "root"; $password = "root"; $database = "komal"; $connection = mysql_connect($host,$user,$password) or die("Could not connect: ".mysql_error()); mysql_select_db($database,$connection) or die("Error in selecting the database:".mysql_error()); $sql="insert into stu(name,class) values('komal',12)"; echo "Insertion Successful ..."; echo "</table>"; mysql_close($connection); ?>
Insertion Successful ...
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles