Sunday, 17 February 2013

How to insert data permanently in DB using Mysql

Step 1:   Create a HTML form using .php extension. for e.g.

<html>
<body>
<form name="Registration" action="" method="post">
<table border="1" width="50%" cell spacing="0" cell padding="0">
<tr>
<td>
<table>
<tr>
<td><h1 align="center">REGISTRATION</h1></td>
</tr>
<tr>
<td>NAME:</td>
<td><input type="text" name="name" size="20" id="name"></td>
</tr>
<tr>
<td>USERNAME:</td>
<td><input type="text" name="uname" size="20" id="uname"></td>
</tr>
<tr>
<td align="center"><input type="submit" name="submit" value="submit" ></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>

Step 2:  Create a database in PHPmyadmin.

Step 3:   Create a table in database.

Step 4:   Make a connection file in common file. for e.g.:
<?php
$conn=mysql_connect("localhost","root","");
if(!$conn)
{
die('couldnot connect:'.mysql_error());
}
mysql_select_db("online_property",$conn);
?>

Step 5:  

1.  Call a connection file on the top.

<?php include ("include/connection.php");

2.  if(isset($_POST['submit'])=='submit')

{

$name=$_POST['name'];

$uname=$_POST['uname'];

echo "You are".$name."".$uname."<br/>";

}

3. Add the insertion query for e.g.:

$query="insert into register(name,uname)value('$name','$uname')";

4. Run the query for e.g.: 

$result=mysql_query($query);

5. Then check the result if result is one then output is successfully register otherwise output is failed.

if($result=='1')

{

echo"Successfully Register";

}

else

{

echo"Registration failed. please try again";

}


?> 


  



No comments:

Post a Comment