News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Adding data to table

Started by VelMurugan, Dec 16, 2008, 09:47 PM

Previous topic - Next topic

VelMurugan

Adding data to table

To add data to table, we need to build and execute a SQL query. PHP provides the mysql_query() function for that purpose. mysql_query() requires two inputs: first, the SQL query and second, a link identifier. Identifer is optional. If omited, then query is sent to the database server to which you last connected.

mysql_query() returns true if the query executes successfully. If there are any syntax errors or if you do not have permission to access database, then it return false.

Code 4 :- adddata.php
<html>
<head>
  <title>Server test Page </title>
</head>
<body>
  <p>Display data from MySQL Database.</p>
  <?php
   $link 
mysql_connect("mysql_host""mysql_user""mysql_password") or die("Could not connect : " mysql_error());
   print 
"Connected successfully<p>";
   
$DB "user";
   
$table "visitor";
   
mysql_select_db($DB) or die ("Database $DB not select.." mysql_error());
   print 
"Successfully select the Database: $DB ";
   
$query "INSERT INTO $table(name,address,email) values('max','nagpur',' test@yahoo.co.inThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it ')";
   if ( ! 
mysql_query$query$link) )
    die ( 
"MySQL error.....<p>" .mysql_error() );
   print 
"<p>Successfully data added to table : $table";
  
?>

</body>
</html>


The adddata.php produces output as shown in Output-4.

QuoteOutput 4: adddata.php
Display data from MySQL Database.
Connected successfully
Successfully select the Database: user
Successfully data added to table : visitor

Source : Techxcel