Saturday, December 28, 2013

insert into Database

here I am going to tellyou how to connect database into php code and how to send Data into Databasethe following code shows you that connectivity and this is enter data into database....\


ther is a very important thing that the name of Database
name of table 
name of entity
name of name inot first page and name into html page  




index.php
<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>

---------------------
 insert2.php


<html>
<body>
<?php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("DB_name", $con);                             //// database name
$sql="INSERT INTO nametable (firstname, lastname)  ////table name
VALUES  ('$_POST[fname]','$_POST[lname]')";   /////////////// name is same as into first page declared...
if (!mysql_query($sql,$con))                                      //////
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con)
?>
</body>

</html>

No comments:

Post a Comment

GitHub repository using Git Bash command

  To add a project to a GitHub repository using Git Bash command line, you can follow these steps: Create a new repository on GitHub by logg...