Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

PHP SQL Query Insert

This example illustrates how to execute insert query in php application.

Ads

PHP SQL Query Insert

     

This example illustrates how to execute insert query in php application.

To understand how to use sql insert queries in php, we have created insertquery.php page. First, connection from database is created using mysql_connect("hostName", "userName", "Password"), selected the database by mysql_select_db("databaseName", connectionObject). Now, queries can be executed using mysql_query() method to insert values into the database.

Table: users (before insertion)

Source Code of insertquery.php 

<?php
  $con = mysql_connect("localhost","root","root");
  if (!$con) {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);

  mysql_query("INSERT INTO users (username, password, email) VALUES ('Gaurvi', 
  'gaurvi', '[email protected]')");

  mysql_query("INSERT INTO users (username, password, email) VALUES ('Hardeep', 
  'hardeep', '[email protected]')");

  $result = mysql_query("SELECT * FROM users ORDER BY username desc");
  echo "<table border='1'>
  <tr>
  <th>Name</th>
  <th>password</th>
  <th>Email</th>
  </tr>";
  while ($row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "</tr>";
  }
  echo "</table>";

  mysql_close($con);
?> 

Download Source Code

Output:

Advertisements

Share on Google+Share on Google+

PHP SQL Query Insert

Posted on: January 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: PHP SQL Query Insert  

Post your Comment


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

Ads

 

Ads