Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php include_once 'database.php';
if(count($_POST)>0) {
    date_default_timezone_set("Asia/Kathmandu");
    $insertdate = date("Y-m-d H:i:s");
    	
    $img = file_get_contents($_FILES['image']['tmp_name']);
    
    mysqli_query($conn,"update report set id='" . $_POST['id'] . "', name='" . $_POST['name'] . "', contactno='" . $_POST['contactno'] . "', address='" . $_POST['address'] . "' ,labno='" . $_POST['labno'] . "',age='" . $_POST['age'] . "',gender='" . $_POST['gender'] . "',refdoctor='" . $_POST['refdoctor'] . "',image='" . $img . "' WHERE id='" . $_GET['id'] . "'");
    	
    if(mysqli_affected_rows($conn)){
        $message = "Record Modified Successfully";
    }else{
        $message = "Record Not Modified Successfully";
    }
}
?>

PHP
<?php
$id = isset($_GET['id']) ? $_GET['id'] : '';

$result = mysqli_query($conn,"SELECT * FROM report WHERE id='$id'");
$row= mysqli_fetch_array($result);

?>

HTML
<!doctype html>
<meta charset="utf-8">
<title>form add

<div class="container-fluid">
  <div class="panel panel-default">
    <div class="panel-heading" style="background-color: aqua">
      <h3 class="panel-title" style="text-align: center">Add form</h3>
    </div>
    <div class="panel-body"> 
    
  <div><?php if(isset($message)) { echo $message; } ?>
</div> 
<div style="padding-bottom: 5px">
<a href="display.php">Patient Report</a>
</div>
  <table class="table table-bordered table-responsive"><tbody><tr>     <td>ID.</td><td>        
        
        </td>    </tr>    <tr>     <td>Name.</td>        <td></td>    </tr>    <tr>     <td>Contact No.</td>        <td></td>    </tr> <tr>     <td>Address</td>        <td></td>    </tr><tr>     <td>Lab No.</td>        <td></td>    </tr><tr>     <td>Age</td>        <td></td>    </tr><tr>     <td>Gender</td>        <td> <div class="col-sm-6">

<input type="radio" name="gender" id="gender1"  value="male"<?php echo $row['gender']=="male"?>/>Male

<input type="radio" name="gender" id="gender2" value="female"<?php echo $row['gender']=="female" ?>/>Female
</div></td>    </tr><tr>     <td>Ref.Doctor</td>        <td></td>    </tr><tr>     <td>Insert Report Img.</td>        <td>        <?php echo ''; ?>
        </td>    </tr><tr>        <td colspan="2" style="text-align: center; background-color: aqua">
           
        
        </td>    </tr></tbody></table>
 
    
<?
	  mysqli_close($conn);
	  ?>
    </div>
    <div class="panel-footer" style="text-align: center">"We Wish You a Good Health"</div>
  </div>
</div>


What I have tried:

PHP
<?php include_once 'database.php';
if(count($_POST)>0) {
    date_default_timezone_set("Asia/Kathmandu");
    $insertdate = date("Y-m-d H:i:s");
    $img = file_get_contents($_FILES['image']['tmp_name']);
    mysqli_query($conn,"update report set id='" . $_POST['id'] . "', name='" . $_POST['name'] . "', contactno='" . $_POST['contactno'] . "', address='" . $_POST['address'] . "' ,labno='" . $_POST['labno'] . "',age='" . $_POST['age'] . "',gender='" . $_POST['gender'] . "',refdoctor='" . $_POST['refdoctor'] . "',image='" . $img . "' WHERE id='" . $_GET['id'] . "'");
    	
    if(mysqli_affected_rows($conn)){
        $message = "Record Modified Successfully";
    }else{
        $message = "Record Not Modified Successfully";
    }
}
?>
Posted
Updated 28-Mar-18 0:50am
v2
Comments
Jochen Arndt 28-Mar-18 7:13am    
It is nearly impossible to answer that without having access to your database and knowing how the PHP code is called when posting the form.

"All field data is update but image is not update"
I read that as "no errors occured and all passed field data except the image data are updated."
If so, the only possible reason is that the UPDATE command passes the same data as alredy stored.

BTW:
Why you are using $_GET in the WHERE clause?
That requires that you call the script with "?id=value" and it will change that recordset with the probability of changing the ID when $_POST['id'] is different.
Member 13751016 29-Mar-18 1:44am    
this is database.php file
<?php
$servername='localhost';
$username='root';
$password='';
$dbname = "labrptdb";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect My Sql:' .mysql_error());
}
?>
Member 13751016 29-Mar-18 2:01am    
and the database create table is
CREATE TABLE IF NOT EXISTS `report` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(250) NOT NULL,
`contactno` varchar(30) NOT NULL,
`address` varchar(250) DEFAULT NULL,
`labno` int(9) DEFAULT NULL,
`age` int(9) DEFAULT NULL,
`gender` varchar(30) DEFAULT NULL,
`refdoctor` varchar(250) DEFAULT NULL,
`image` longblob,
`datetime` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900