[英]Issue In Update database Query?
I am new in php and as well in database. 我是php和数据库中的新手。 I am facing issue to update table in database.
我面临更新数据库中表的问题。 i am getting values in input field but when i update query is not working.
我在输入字段中获取值,但是当我更新查询时无法正常工作。
$edit_id=$_GET['edit_id'];
$get_data = mysqli_query($con, "SELECT * FROM userform WHERE id='$edit_id' ");
$run = mysqli_fetch_array($get_data);
if (!$run) {
echo "something went wrong";
}
else{
echo "Working Fine";
}
if(isset($_POST['update'])){
$name = $_POST['name'];
$email = $_POST['email'];
$subjects = $_POST['subjects'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$city = $_POST['city'];
$address = $_POST['address'];
$position = $_POST['position'];
$about = $_POST['about'];
$query = mysqli_query($con, "UPDATE userform SET name='$name', email='$email', subjects='$subjects', phone='$phone', country='$country', city='$city', address='$address', position='$position', about='$about', WHERE id='$edit_id' ");
//$run = mysqli_query($query);
if ($query) {
echo "<script>alert('User Date Inserted Successfully'); </script>";
//header('location:records.php');
}
else{
echo "<br> Something went wrong";
}
exit();
}
?>
<div id="outer">
<form method="POST" enctype="multipart/form-data">
<input type="text" name="name" value="<?php echo $run['name']; ?>" >
<input type="email" name="email" value="<?php echo $run['email']; ?>" >
<input type="text" name="subjects" value="<?php echo $run['subjects']; ?>" >
<input type="text" name="phone" value="<?php echo $run['phone']; ?>" >
<input type="text" name="country" value="<?php echo $run['country']; ?>" >
<input type="text" name="city" value="<?php echo $run['city'] ?>" >
<input type="text" name="address" value="<?php echo $run['address']; ?>" >
<input type="text" name="position" value="<?php echo $run['position']; ?>" >
<textarea name="about" value="<?php echo $run['about']; ?>" ></textarea>
<input id="sbmt" type="submit" value="Update Value" name="update">
</form>
</div>
Remove the trailing ,(comma) from your update query. 从您的更新查询中删除尾随(,逗号) 。 Just before
WHERE
there is a comma which let compiler think there should be another column which need to be updated. 在
WHERE
之前有一个逗号,它使编译器认为应该有另一列需要更新。 So just remove that. 所以就删除它。 So remove the , after
$about
. 所以去除,之后
$about
。
First you have to remove ,
(comma) after '$about'
in your update query. 首先,您必须在更新查询中的
'$about'
之后删除,
(逗号)。 It should be like below. 它应该像下面这样。
$query = mysqli_query($con, "UPDATE `userform` SET name='$name', email='$email', subjects='$subjects', phone='$phone', country='$country', city='$city', address='$address', position='$position', about='$about' WHERE id='$edit_id' ");
And one more thing, If you are using textarea as input then you should replace '
with \\'
for update the data in mysql.So your $run['about']
should be replaced like below. 还有一件事,如果您使用textarea作为输入,则应将
'
替换为\\'
以更新mysql中的数据。因此,您的$run['about']
应该如下替换。
$run['about']=str_replace("'","\\'",$run['about']);
Let make this changes first. 让我们先进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.