我对PHP并不那么熟悉。我还在一步一步地学习。在我的代码中,已经声明了post操作中将获取数据的名称。我无法看到问题的原因,因为我认为我做了它需要做的事情。
PHP代码
<?php
$userID = $_POST['txtUserId'];
$fname = $_POST['txtFname'];
$mname = $_POST['txtMname'];
$lname = $_POST['txtLname'];
$noSt = $_POST['txtNoStreet'];
$city = $_POST['txtCity'];
$contactNo = $_POST['txtContactNo'];
$dob = $_POST['txtDOB'];
$age = $_POST['txtAge'];
$selectMaleGender = $_POST['selGender'];
$selectFemaleGender = $_POST['selGender'];
if(!empty($_GET['userid']) || isset($_GET['userid'])){
selectUsersUsingId($uid);
enableComponents();
}
if(isset($_POST['btnSearch'])){
if(empty($userID))
$msg = "User ID is empty!";
else{
selectUsersUsingId($userID);
}
}else if (isset($_POST['btnUpdate'])){
mysqli_query($con, "update tblusers set fname= '$_POST[txtFname]', mname = '$_POST[txtMname]', lname = '$_POST[txtLname]', no_street = '$_POST[txtNoStreet]', city = '$_POST[txtCity]', contact_no = '$_POST[txtContactNo]', dob = '$_POST[txtDOB]', age = '$_POST[txtAge]', gender = '$_POST[selGender]' where user_id = '$_POST[txtUserId]'") or die(mysqli_error());
$msg = "Successfully updated the record!";
disableComponents();
}else if(isset($_POST['btnDelete'])){
mysqli_query($con, "delete from tblusers where user_id = '$_POST[txtUserId]'") or die(mysqli_error());
mysqli_query($con, "delete from tblaccount where user_id = '$_POST[txtUserId]'") or die(mysqli_error());
$msg = "Successfully deleted the record!";
disableComponents();
}
?>
这是我的表格
<form name="editdelete_user_form" method="POST" action="admin_editdelete_user.php">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="border border_tlr border_ts border_ls border_bs col_1">Search by:</td>
<td class="border border_ts border_bs col_1"><input type="text" name="txtUserId" value="<?php echo $userID; ?>" /></td>
<td colspan="2" class="border border_ts border_bs border_rs border_trr"><input class="src_btn" type="submit" name="btnSearch" value="Search" /></td>
</tr>
<tr>
<td class="border border_ls col_1"><br></td>
<td class="border col_2">First</td>
<td class="border col_2">Middle</td>
<td class="border border_rs col_2">Last</td>
</tr>
<tr>
<td class="border border_ls border_bs col_1">Name:</td>
<td class="border border_bs col_2"><input type="text" name="txtFname" value="<?php echo $fname; ?>" <?php echo $txtFnameDisable; ?> /></td>
<td class="border border_bs col_2"><input type="text" name="txtMname" value="<?php echo $mname; ?>" <?php echo $txtMnameDisable; ?> /></td>
<td class="border border_bs border_rs col_2"><input type="text" name="txtLname" value="<?php echo $lname; ?>" <?php echo $txtLnameDisable; ?> /></td>
</tr>
<tr>
<td class="border border_ls col_1"><br></td>
<td class="border col_2">No. and Street</td>
<td class="border col_2">City</td>
<td class="border border_rs col_2">Contact No.</td>
</tr>
<tr>
<td class="border border_ls border_bs col_1">Address:</td>
<td class="border border_bs col_2"><input type="text" name="txtNoStreet" value="<?php echo $noSt; ?>" <?php echo $txtNoStreetDisable; ?> /></td>
<td class="border border_bs col_2"><input type="text" name="txtCity" value="<?php echo $city; ?>" <?php echo $txtCityDisable; ?> /></td>
<td class="border border_bs border_rs col_2"><input type="text" name="txtContactNo" value="<?php echo $contactNo; ?>" <?php echo $txtContactNoDisable; ?> /></td>
</tr>
<tr>
<td colspan="2" class="border border_ls col_1"><br></td>
<td class="border col_2">Age</td>
<td class="border border_rs col_2">Gender</td>
</tr>
<tr>
<td class="border border_ls border_bs col_1">Date of Birth</td>
<td class="border border_bs col_2"><input type="text" name="txtDOB" value="<?php echo $dob; ?>" <?php echo $txtDOBDisable; ?> /></td>
<td class="border border_bs col_2"><input type="text" name="txtAge" value="<?php echo $age; ?>" <?php echo $txtAgeDisable; ?> /></td>
<td class="border border_bs border_rs col_2">
<select name="selGender" <?php echo $txtGenderDisable; ?> class="col_1"><option></option ><option <?php echo $selectMaleGender; ?>>Male</option><option <?php echo $selectFemaleGender; ?>>Female</option></select>
</td>
</tr>
</table>
<div class="marginleft_1">
<input class="margintop_2 sub_btn" type="submit" name="btnUpdate" value="Update" <?php echo $btnUpdateDisable; ?> />
<input class="margintop_2 sub_btn" type="submit" name="btnDelete" value="Delete" <?php echo $btnDeleteDisable; ?> />
</div>
</form>