I am trying to update the mysql database using PHP but somehow I am not able to do the same. It echos the message that it is successfully updated but it doesn't update it. Please help. Please check the code and tell me the correction: First I am showing the form then the PHP code
<?php
$id=$_GET['id'];
$sql="select * from members_data where id='$id'";
$data=mysql_query($sql);
$row=mysql_fetch_array($data);
?>
<form method="post" action="edit1.php" name="form1" enctype="multipart/form-data">
<table width="400" align="left">
<tr>
<td style="width:300px;">
Name
</td>
<td><input placeholder="What's the latest news?" type="text" name="name" style="height:20px; width:300px;" value="<?php echo $row['name']?>" /></td>
</tr>
<tr>
<td style="width:300px;">
Family Image
</td>
<td width="69%" height="25"><input type="file" name="file" style="height:20px; width:300px;" /></td>
</tr>
<tr>
<td style="width:300px;">
Membership No.
</td>
<td><input placeholder="What's your membership number?" type="text" name="membership_no" style="height:20px; width:300px;" value="<?php echo $row['membership_no']?>" /></td>
</tr>
<tr>
<td style="width:300px;">
Address
</td>
<td><input placeholder="What's the latest news?" type="text" name="address" style="height:20px; width:300px;" value="<?php echo $row['address']?>" /></td>
</tr>
<tr>
<td style="width:300px;">
Contact Number
</td>
<td><input placeholder="What's the latest news?" type="text" name="contact_no" style="height:20px; width:300px;" value="<?php echo $row['contact_no']?>" /></td>
</tr>
<tr>
<td>
<input type="hidden" name="id" value="<?php echo $res['id']?>" />
</td>
<td style="text-align:right; width:300px;"><input type="submit" name="edit1" value="Update" /></td>
</tr>
</table>
</form>
Now starts the php code:
<?php
include("conn.php");
?>
<?php
if(isset($_POST['edit1']))
{
$allowedExts = array("gif", "jpeg", "jpg", "png", "pdf", "doc", "docx");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "text/plain")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
//echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
//echo "Upload: " . $_FILES["file"]["name"] . "<br />";
//echo "Type: " . $_FILES["file"]["type"] . "<br />";
//echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("images/family_pics/" . $_FILES["file"]["name"]))
{
//echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/family_pics/" . $_FILES["file"]["name"]);
//echo "Stored in: " . "images/" . $_FILES["file"]["name"];
}
}
}
else
{
//echo "Invalid file";
}
$id=$_POST['id'];
$name=$_POST['name'];
$image=$_FILES["file"]["name"];
$membership_no=$_POST['membership_no'];
$address=$_POST['address'];
$contact_no=$_POST['contact_no'];
$query=mysql_query("update members_data set name='$name',family_image='$image',membership_no='$membership_no',address='$address',contact_no='$contact_no' WHERE id='$id'") or die(mysql_error());
// if successfully updated.
if($query){
echo "Successful";
echo "<BR>";
echo "<a href='admin_detail.php'>View result</a>";
}
else {
echo "ERROR";
}
}
?>
<?php /*?><script type="text/javascript">window.location="edit_records.php"</script><?php */?>