<?php
include 'header.php';
$id = $_GET['id'];
?>
<form action="" method="post" id="validation-form" class="form-horizontal" enctype='multipart/form-data' >
<div class="control-group">
<label class="control-label" for="file">Change Image</label>
<div class="controls">
<input type="file" name="file" id="imgae" value="<?php echo $image;?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">Change Name</label>
<div class="controls">
<input type="text" class="input-large" name="name" id="name" value="<?php echo $name;?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="message">Change Description</label>
<div class="controls">
<textarea class="span4" name="message" id="message" rows="4"><?php echo $message;?></textarea>
</div>
</div>
<div class="controls">
<input type="hidden" name="id" value=<?php echo $_GET['id'];?>>
<input type='submit' class="btn btn-danger btn" name='but_upload' value="Submit" >
<!-- <button type="submit" class="btn btn-danger btn">Validate</button> -->
<a href="elements.php" class="btn"> back </a>
用于编辑数据的代码
$time_stamp = time();
$image = $_FILES['file']['name'];
$image = $time_stamp . '_' . $image;
$target_dir = "img/upload/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$extensions_arr = array("jpg","jpeg","png","gif");
$location = 'img/upload/'.$image;
if( in_array($imageFileType,$extensions_arr) ){
move_uploaded_file($_FILES['file']['tmp_name'],'img/upload/'.$image);
}
$name = $_POST['name'];
$message = $_POST['message'];
$query = "insert into images(image,location,name,message) values('$image', '$location', '$name', '$message')";
mysqli_query($con,$query) or die(mysqli_error($con));
echo "<script>document.location.href='elements.php?msg=Updated'</script>";
<!-- -->
用于更新数据的代码
$name = $_POST['name'];
$message = $_POST['message'];
$query = "UPDATE images SET image = '$image', location = '$location', name = '$name', message = '$message' where id = '$id'";
mysqli_query($con,$query);
echo "<script>document.location.href='elements.php?msg=Updated' </script>" ;
}
include 'footer.php'; ?>
这是用于向数据库中添加和更新数据的代码。使用此代码,我可以将数据添加或编辑到数据库中。我无法将数据成功编辑到数据库中,但是问题是我尝试更新数据时未在插入字段中显示数据,因此请在更新数据时帮助在插入字段中显示数据。
答案 0 :(得分:0)
<?php
$id = $_GET['id'];
$sql = "SELECT * FROM users WHERE id ='1'";
$result =mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);
?>
By using this code on the top of the page then we can show the values in the fields and able to update the existing data
$ row = mysqli_fetch_assoc($ result);帮助从数据库中搜索并提供要获取的行并显示 通过在数据库中给定的行名替换为行名,数据库中将显示数据库中的数据