Friday, January 3, 2014

Insert into Data Base Using PHP

Here i am going to tell you how to insert data into database and how can we connect a php page to the database 
the connection is made in php page by using the query in html page.



<html>
<body>
<h1>A small example page to insert some data in to the MySQL database using PHP</h1>
<form action="insert2.php" method="post">
Firstname: <input type="text" name="fname" /><br><br>
Lastname: <input type="text" name="lname" /><br><br>
<input type="submit" />
</form>
</body>
</html>

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

mysql_select_db("sun12k", $con);
$sql="INSERT INTO nametable (firstname, lastname)
VALUES
('$_POST[fname]','$_POST[lname]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con)
?>
</body>
</html>

1 comment:

  1. My friend Suggest me this blog and I can say this is the best blog to get the basic knowledge.Thank you so much for this Selenium Training in Chennai

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...