Home Sql Mysql-table PHP SQL Insert Statement

Related Tutorials


 
 

Share on Google+Share on Google+

PHP SQL Insert Statement

Advertisement
PHP SQL Insert Statement show you the message when the records are inserted successfully into table "stu''.

PHP SQL Insert Statement

     

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`)                    
        )

phpsqlinsertion.php:

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);
?>

Output

Insertion Successful ...
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 3, 2006

Related Tutorials

Discuss: PHP SQL Insert Statement  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com