我正在尝试更新管理员mysql表上的记录。但是当我尝试这种方法时仍然没有变化..我无法看到这个代码的问题..
info.php的
<?php
$query = "SELECT * from admin where username = '{$_SESSION['login_user']}'";
$result = mysqli_query($conn,$query);
while($row=mysqli_fetch_assoc($result))
{
echo '<input type="text" class="form-control" name="user_id" disabled value='.$row['user_id'].'>';
echo '<input type="text" class = "form-control" name = "lastname" value='.$row['lname'].'>';
echo '<input type="text" class = "form-control" name = "firstname" value='.$row['fname'].'>';
echo '<input type="text" class = "form-control" name = "middlename" value='.$row['mname'].'>';
echo '<input type="text" class = "form-control" name = "address" value='.$row['address'].'>';
echo '<input type="text" class = "form-control" name = "contact" value='.$row['contact'].'>';
echo '<input type="text" class = "form-control" name = "email_add" value='.$row['email_add'].'>';
echo '<input type="text" class = "form-control" name = "username" value='.$row['username'].'>';
echo '<input type="password" class = "form-control" name = "password" value='.$row['password'].'>';
echo '<input type="password" class = "form-control" name = "confirmPassword" value='.$row['conf_pass'].'>';
}?>
<button type="submit" class="btn btn-primary" name="update">Submit</button>
update.php ----我不知道它有什么问题。
<?php
include('pgconnect.php');
if(isset($_GET['update'])){
$acctid = $_GET['user_id'];
$lname = $_GET['lastname'];
$fname = $_GET['firstname'];
$mname = $_GET['middlename'];
$address = $_GET['address'];
$contact = $_GET['contact'];
$email = $_GET['email_add'];
$user = mysql_real_escape_string($_GET['username']); # use whatever escaping function your db requires this is very important.
$pass = mysql_real_escape_string($_GET['password']);
$confpass = mysql_real_escape_string($_GET['confirmPassword']);
$sql = "UPDATE admin SET lname='$lname', fname='$fname', mname ='$mname', address='$address' contact = $contact, email_add = '$email', username ='$user',password = '$pass', conf_pass = '$confpass' where user_id = '$acctid'";
$result = mysqli_query($conn,$sql);
echo "$sql";
if($result){
echo"Succesully Updated!";
}
else
{
echo"Cannot be Updated!";
}
mysqli_close($conn);
}?>
答案 0 :(得分:1)
了解表格背后的机制:
的index.html:
<form action="update.php?param=234" method="post">
<input type="text" name="firstfield" />
<button name="update">Submit</button>
</form>
update.php:
<?php
echo $_GET['param']; //should output 234
echo $_POST['firstfield']; //should output whatever you put in your textfield
var_dump($_POST['update']); //should return something
你注意到了,参数之后?在您的操作中,作为GET值传递,所有其他值都是POST值。