查询字符串值未获取 [英] Query string value is not fetching
本文介绍了查询字符串值未获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法从查询字符串中读取id。
当我点击编辑链接时我正确地读取了行没有问题但是当我更新时数据ID没有取出因此我的查询不起作用。
I am not able to read id from query string.
When i click edit link I am reading the the row correctly with no issue but when i update the the data id is not fetching and hence my query doesn't work.
$id = $_GET['id'];
set null when clicking update button. thats why query is not running
我尝试了什么:
What I have tried:
<?php
include 'master/header.php';
include 'config.php';
include './functions/functions.php';
?>
<?php
$id = "";
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$sql = "SELECT * FROM user WHERE id =$id ";
$result = $conn->query($sql);
$row = mysqli_fetch_assoc($result);
if (isset($_POST['submit'])) {
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$query = "UPDATE user SET firstname='$firstName',lastName='$lastName',email='$email',username='$username',password='$password' WHERE id= $id";
echo $query;
$updateResult = $conn->query($query);
if (!$updateResult ) {
die("qery not works" . mysqli_error($conn));
} else {
header("location: index.php");
}
}
?>
<h1 class="text-center">Edit User</h1>
<form action="edit.php" method="post">
<div class="container">
<div class="row">
<input type="hidden" class="" for="" value="<?php
?>">
<label class="col-lg-6" for="firstName">First name</label>
<input type="text" class="form-control col-lg-6" maxlength="25" name="firstName" placeholder="Enter First name" value="<?php
if (isset($row['firstname'])) {
echo $row['firstname'];
}
?>" >
</div>
<div class="row">
<label class="col-lg-6" for="lastName">Last name</label>
<input type="text" maxlength="25" class="form-control col-lg-6" name="lastName" placeholder="Enter Last name" value="<?php
if (isset($row['lastName'])) {
echo $row['lastName'];
}
?>" >
</div>
<div class="row">
<label class="col-lg-6" maxlength="50" for="lastName">Email</label>
<input type="text" class="form-control col-lg-6" name="email" placeholder="Enter Email" value="<?php
if (isset($row['email'])) {
echo $row['email'];
}
?>" >
</div>
<div class="row">
<label class="col-lg-6" for="username">Username</label>
<input type="text" maxlength="50" class="form-control col-lg-6" name="username" placeholder="Enter username" value="<?php
if (isset($row['username'])) {
echo $row['username'];
}
?>">
</div>
<div class="row">
<label for="password" class="col-lg-12">Password</label>
<input type="password" class="form-control col-lg-12" name="password" placeholder="Enter password" value="<?php
if (isset($row['password'])) {
echo $row['password'];
}
?>">
</div>
<div class="row">
<label for="confirmPassword" class="col-lg-12">Confirm Password</label>
<input type="password" class="form-control col-lg-12" name="confirmPassword" placeholder="confirm password" >
</div>
<div class="row">
<input type="submit" class="btn btn-primary" name="submit" value="update" >
</div>
</div>
</form>
推荐答案
id =
_GET ['id ];
单击更新按钮时设置为null。这就是为什么查询没有运行
_GET['id']; set null when clicking update button. thats why query is not running
我尝试了什么:
What I have tried:
<?php
include 'master/header.php';
include 'config.php';
include './functions/functions.php';
?>
<?php
id =;
if(isset(
id = ""; if (isset(
这篇关于查询字符串值未获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文