Insert Data Using PHP Mysqli
<form id="form1" name="form1" method="post" >
<table width="445" height="394" border="1" align="center">
<tr>
<td>Name</td>
<td>
<input type="text" name="name" />
</td>
</tr>
<tr>
<td>email</td>
<td>
<input type="email" name="email" />
</td>
</tr>
<tr>
<td>address</td>
<td><textarea name="address"></textarea></td>
</tr>
<tr>
<td>mobile no.</td>
<td>
<input type="text" name="mobile" />
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit" /></td>
<td>
<input type="button" name="cancel" value="cancle" />
</td>
</tr>
</table>
</form>
<?php
$con=mysqli_connect("localhost","root","root","example") or die(mysqli_error());
if(isset($_POST['submit']))
{
extract($_POST);
$q=mysqli_query($con,"insert into student_info(name,email,address,m_no) values ('$name','$email','$address','$mobile')") or die(mysqli_error($con));
if($q)
{
echo"<script>";
echo"alert('Record Added');";
echo"</script>";
}
else
{
echo"<script>";
echo"alert('Error While Inserting Record.....');";
echo"</script>";
}
}
?>
<table width="445" height="394" border="1" align="center">
<tr>
<td>Name</td>
<td>
<input type="text" name="name" />
</td>
</tr>
<tr>
<td>email</td>
<td>
<input type="email" name="email" />
</td>
</tr>
<tr>
<td>address</td>
<td><textarea name="address"></textarea></td>
</tr>
<tr>
<td>mobile no.</td>
<td>
<input type="text" name="mobile" />
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit" /></td>
<td>
<input type="button" name="cancel" value="cancle" />
</td>
</tr>
</table>
</form>
<?php
$con=mysqli_connect("localhost","root","root","example") or die(mysqli_error());
if(isset($_POST['submit']))
{
extract($_POST);
$q=mysqli_query($con,"insert into student_info(name,email,address,m_no) values ('$name','$email','$address','$mobile')") or die(mysqli_error($con));
if($q)
{
echo"<script>";
echo"alert('Record Added');";
echo"</script>";
}
else
{
echo"<script>";
echo"alert('Error While Inserting Record.....');";
echo"</script>";
}
}
?>
Comments
Post a Comment