Monday 8 July 2013

Insert to DataBase in php using mysql

//index.php 

// Insert to DataBase in php using mysql

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="regcode.php" >
 <table width="299" border="0" align="center">
      <tr>
        <td colspan="2" align="center"><font color="red" size="+1">Employee Registration Form</font></td>
      </tr>
      <tr>
        <td width="143" align="left">&nbsp;</td>
        <td width="264" align="left">&nbsp;</td>
      </tr>
      <tr>
        <td align="left">Name</td>
        <td align="left"><label for="name"></label>
        <input name="name" type="text" id="name" size="25" placeholder="Enter ur Name" /></td>
      </tr>
       <tr>
        <td align="left">Phone No</td>
        <td align="left"><label for="phone_no"></label>
        <input name="phone_no" type="text" id="phone_no" size="25" maxlength="10" placeholder="Enter Phone Number" /></td>
      </tr>
      <tr>
        <td align="left">Email Id</td>
        <td align="left"><label for="email_id"></label>
        <input name="email_id" type="text" id="email_id" size="25" /></td>
      </tr>
      <tr>
        <td align="left">User Name</td>
        <td align="left"><label for="username"></label>
        <input name="username" type="text" id="username" onKeyUp="loadXMLDoc(this.value)" size="25"/></td>
      </tr>
      <tr>
        <td align="left">Password</td>
        <td align="left"><label for="password"></label>
        <input name="password" type="password" id="password" size="25" /></td>
      </tr>
      <tr>
        <td align="right"><input type="submit" name="submit" id="submit" value="Submit" /></td>
        <td align="center"><input type="reset" name="reset" id="reset" value="Reset" /></td>
      </tr>
    </table>
    <div align="center"></div>
</form>
</form>
</body>
</html>



//regcode.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$name=$_REQUEST['name'];

$phone_no=$_REQUEST['phone_no'];
$email_id=$_REQUEST['email_id'];
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];

$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="insert into reg values('$name','$phone_no','$email_id','$username','$password')";
$query=mysql_query($sql);

if(query==true)
{
echo "Registraion Success"."<br/>";    
    echo "Welcome To"." ".$name."<br/>";
}
else
{
    echo "failed";
}


?>
</body>
</html>





No comments:

Post a Comment