Hello every one.
I am creating a form in php and trying to work with button in that. There are 3 buttons below then form.
1. Submit.(to insert data in BD)
2. Update.(to update data in table in DB)
3. Delete.(to delete data from table in DB)
When I apply the code, its not working fine. Someone direct me to use php functions or php statements. Please guide me how can i use "if" "else-if" or "switch" statement.
The code is shown below.
<h1>EDIT MEDICINE & SURGICAL EQUIPMENT RECORD </h1>
<p>Enter New Item's Data.</p>
<form id="form" name="form" method="post" action="">
<table width="563" border="0" bgcolor="#FFFFCC">
<tr>
<td width="261" height="56">Item ID:
<input name="mid" type="text" /></td>
<td width="286">Item's Name :
<input type="text" name="mname" /></td>
</tr>
</table>
<label><br />
<br /></label>
<label></label>
<input name="Save" type="submit"/>
<?php
$con=mysqli_connect("localhost","root","","bsc_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO med_t (mid, mname)
VALUES
('$_POST[mid]','$_POST[mname]')";
if (!mysqli_query($con,$sql))
{
//die('Error:' . mysqli_error());
}
else
{
echo "1 record added";
}
mysqli_close($con);
?>
|
<input name="Save2" type="submit" value="Update"/>
<?php
$con=mysqli_connect("localhost","root","","bsc_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"UPDATE med_t SET mname=('$_POST[mname]')
WHERE mid=('$_POST[mid]')");
if (!mysqli_query($con,$sql))
{
//die('Error:' . mysqli_error());
}
else
{
echo "1 record Updated";
}
$url="medicine.php";
mysqli_close($con);
?>
|
<label></label>
<label></label>
<label>
<input name="Save22" type="submit" value="Delete"/>
<?php
$con=mysqli_connect("localhost","root","","bsc_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"DELETE FROM med_t WHERE mid=('$_POST[mid1]')");
if (!mysqli_query($con,$sql))
{
//die('Error:' . mysqli_error());
}
else
{
echo "1 record deleted";
}
$url="medicine.php";
mysqli_close($con);
?>
</label>
</form>
Thanks and Regards.
Aamir Karim.