更新
我现在可以让它更新与实际值的编码在一页,而不是2,但它仍然不会更新使用的形式,我已经使它只工作在固定电话,直到我可以得到它的工作从形式。
下面是没有html主体的新代码,html主体有一些到php头的链接;
$search = $_POST['search'];
$search2 = $_POST['search2'];
$results = mysqli_query($connection, "SELECT RecordReference, Dateofrecordcreation, Status, AgentName, ReturnFiledOn, InfoOnline, Surname, Forename, DateofBirth, UTR, NINO, Address, Postcode, AddressAffectiveFrom, Mobile, Landline, Email, Balance FROM `selfemployed` WHERE Surname LIKE '$search' AND Forename LIKE '$search2'");
while($row = mysqli_fetch_array($results))
{
$RecordReference = $row['RecordReference'];
$Dateofrecordcreation = $row['Dateofrecordcreation'];
$Status = $row['Status'];
$AgentName = $row['AgentName'];
$ReturnFiledOn = $row['ReturnFiledOn'];
$InfoOnline = $row['InfoOnline'];
$Surname = $row['Surname'];
$Forename = $row['Forename'];
$DateofBirth = $row['DateofBirth'];
$UTR = $row['UTR'];
$NINO = $row['NINO'];
$Address = $row['Address'];
$Postcode = $row['Postcode'];
$AddressAffectiveFrom = $row['AddressAffectiveFrom'];
$Mobile = $row['Mobile'];
$Landline = $row['Landline'];
$Email = $row['Email'];
$Balance = $row['Balance'];
}
if(isset($_POST['Update']))
$RecRef = $_POST['RecordReference'];
$Datereccr = $_POST['Dateofrecordcreation'];
$Sta = $POST['Status'];
$AgName = $_POST['AgentName'];
$Srnm = $_POST['Surname'];
$Frnm = $_POST['Forename'];
$DoB = $_POST['DateofBirth'];
$NatIn = $_POST['NINO'];
$Add = $_POST['Address'];
$Pstc = $_POST['Postcode'];
$AddAffFrm = $_POST['AddressAffectiveFrom'];
$UTaxR = $_POST['UTR'];
$Mob = $_POST['Mobile'];
$llffs = $_POST['Landline'];
$Eml = $_POST['Email'];
$RetFiled = $_POST['ReturnFiledOn'];
$Bal = $_POST['Balance'];
$Online = $_POST['InfoOnline'];
$id = $_POST['id'];
// Information to update
$sql_query = "UPDATE `selfemployed` SET `Landline` = '$llffs' WHERE RecordReference = '$RecordReference'";
// Update Qquery
mysqli_query($connection, $sql_query);
// Close our connection to the database
mysqli_close($connection);
?>
<!DOCTYPE html>
<html>
<style type="text/css">
<!--
原岗位
我一直在尝试为我的数据库创建一个更新功能,已经被困在这几天了,所以我想我会寻求帮助。代码似乎运行没有问题,没有报告错误,但没有更新。
搜索/显示代码如下所示(除了数据中有空格时不显示所有文本外,此操作正常)
这是搜索和显示代码
require_once "config.php";
$search = $_POST['search'];
$search2 = $_POST['search2'];
$results = mysqli_query($connection, "SELECT RecordReference, Status, ReturnFiledOn, InfoOnline, Surname, Forename, DateofBirth, UTR, NINO, Address, Postcode, AddressAffectiveFrom, Mobile, Landline, Email, Balance FROM `selfemployed` WHERE Surname LIKE '$search' AND Forename LIKE '$search2'");
while($row = mysqli_fetch_array($results))
{
$RecordReference = $row['RecordReference'];
$Dateofrecordcreation = ['Dateofrecordcreation'];
$Status = $row['Status'];
$AgentName = $row['AgentName'];
$ReturnFiledOn = $row['ReturnFiledOn'];
$InfoOnline = $row['InfoOnline'];
$Surname = $row['Surname'];
$Forename = $row['Forename'];
$DateofBirth = $row['DateofBirth'];
$UTR = $row['UTR'];
$NINO = $row['NINO'];
$Address = $row['Address'];
$Postcode = $row['Postcode'];
$AddressAffectiveFrom = $row['AddressAffectiveFrom'];
$Mobile = $row['Mobile'];
$Landline = $row['Landline'];
$Email = $row['Email'];
$Balance = $row['Balance'];
}
// Close our connection to the database
mysqli_close($connection);
?>
<!DOCTYPE html>
<html>
<style type="text/css">
<!--
.style1 {color: #000000}
.style10 {color: #F4A5A4}
.style11 {color: #D3D3D3}
.style14 {color: #000000; font-size: 14px; }
.style15 {font-size: 14px}
.style16 {color: #D3D3D3; font-size: 14px; }
.style17 {color: #F4F2A4; font-size: 14px; }
.style3 {color: #000000; font-size: 18px; font-weight: bold; }
.style8 {color: #ABDEB2}
.style9 {color: #F4F2A4}
.style18 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
<body>
<form action="updateselfemp.php" method="post">
<table width="850" border="0">
<tr>
<td width="420" valign="top" bgcolor="#F4A5A4"><table width="418" border="0">
<tr>
<td align="right">Reference<span class="style10">::</span></td>
<td><label>
<input name="RecordReference" type="text" id="RecordReference" value=<?php echo $RecordReference; ?> >
</label></td>
</tr>
<tr>
<td align="right">Date of Record Creation<span class="style10">::</span></td>
<td><label>
<input type="text" name="Dateofrecordcreation" id="Dateofrecordcreation" value=<?php echo $Dateofrecordcreation; ?> >
</label></td>
</tr>
<tr>
<td width="222" align="right"><span class="style15"><span class="style14">Company Status<span class="style10">:</span></span></span></td>
<td width="186"><select name="Status" id="Status">
<option selected><?php echo $Status; ?></option>
<option value="ACTIVE">ACTIVE</option>
<option value="CLOSED">CLOSED</option>
<option value="DORMANT">DORMANT</option>
<option value="PHOENIX">PHOENIX</option>
<option value="NO LONGER A CUSTOMER">NO LONGER A CUSTOMER</option>
</select></td>
</tr>
<tr>
<td align="right"><span class="style14">Agent Name<span class="style10">:</span>:</span></td>
<td><label>
<input name="AgentName" type="text" id="AgentName" value=<?php echo $AgentName; ?> >
</label></td>
</tr>
</table>
<span class="style1"></span></td>
<td width="420" valign="top" bgcolor="#F4F2A4"><p class="style3">Return Details</p>
<table width="418" border="0">
<tr>
<td width="263" align="right"><span class="style14">Date Return Filed</span><span class="style17">::</span></td>
<td width="145"><label>
<input name="DateReturnFiled" type="text" id="DateReturnFiled" value=<?php echo $ReturnFiledOn; ?> >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">Is this information online?</span><span class="style9">::</span></span></td>
<td><label>
<select name="Online" id="Online">
<option><?php echo $InfoOnline; ?></option>
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="N/A">N/A</option>
</select>
</label></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" bgcolor="#D3D3D3"><p class="style3">Details</p>
<table width="418" border="0">
<tr>
<td width="268" align="right"><span class="style14">Surname</span><span class="style16">::</span></td>
<td width="140"><label>
<input name="Surname" type="text" id="Surname" value=<?php echo $Surname; ?> >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">Forename</span><span class="style11">::</span></span></td>
<td><label>
<input name="Forename" type="text" id="Forename" value=<?php echo $Forename; ?> >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">Date of Birth</span><span class="style11">::</span></span></td>
<td><label>
<input name="DateofBirth" type="text" id="DateofBirth" value=<?php echo $DateofBirth; ?> >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">UTR</span><span class="style11">::</span></span></td>
<td><label>
<input name="UTR" type="text" id="UTR" value=<?php echo $UTR; ?> >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">National Insurance No</span><span class="style11"></span></span></td>
<td><label>
<input name="NINO" type="text" id="NINO" value=<?php echo $NINO; ?> >
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style15"><span class="style1">Address<span class="style11">::</span></span></span></td>
<td><label>
<textarea name="Address" id="Address" cols="25" value=<?php echo $Address; ?> rows="3"></textarea>
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style15"><span class="style1">Postcode</span><span class="style11">::</span></span></td>
<td><label>
<input name="Postcode" type="text" id="Postcode" value=<?php echo $Postcode; ?> >
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style15"><span class="style1">Address Affective From</span><span class="style11">::</span></span></td>
<td><input name="AddressAffectiveFrom" type="text" id="AddressAffectiveFrom" value=<?php echo $AddressAffectiveFrom; ?> ></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style15"><span class="style1">Mobile</span><span class="style11">::</span></span></td>
<td><label>
<input name="Mobile" type="text" id="Mobile" value=<?php echo $Mobile; ?> >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">Landline</span><span class="style11">::</span></span></td>
<td><label>
<input name="Landline" type="text" id="Landline" value="<?php echo $Landline; ?>" >
</label></td>
</tr>
<tr>
<td align="right"><span class="style15"><span class="style1">Email</span><span class="style11">::</span></span></td>
<td><label>
<input name="Email" type="text" id="Email" value=<?php echo $Email; ?> >
</label></td>
</tr>
<tr>
<td align="right"> </td>
<td><label></label></td>
</tr>
</table></td>
<td valign="top" bgcolor="#ABDEB2"><p class="style3">Balance</p>
<table width="418" border="0">
<tr>
<td width="261" align="right"><span class="style14">Outstanding Balance<span class="style8">::</span></span></td>
<td width="147"><label>
<input name="Balance" type="text" id="Balance" value=<?php echo $Balance; ?> >
</label></td>
</tr>
</table>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style1"> </p></td>
</tr>
<tr>
<td> </td>
<td align="right"><label>
<input type="submit" name="Submit" id="Update" value="Update Record">
<input type="hidden" name="id" value"<?php echo $RecordReference; ?>">
</label></td>
</tr>
</table>
</form>
<span class="style18">Current File Content</span>
<table>
<tr><td>Record Reference</td> <td><?php echo $RecordReference; ?></td></tr>
<tr><td>Date of Record Creation</td> <td><?php echo $Dateofrecordcreation; ?></td>
</tr>
<tr><td>Status</td> <td><?php echo $Status; ?></td></tr>
<tr><td>Agent Name</td> <td><?php echo $AgentName; ?></td></tr>
<tr><td>Return Filed On</td> <td><?php echo $ReturnFiledOn; ?></td></tr>
<tr><td>Surname</td> <td><?php echo $Surname; ?></td></tr>
<tr><td>Forename</td> <td><?php echo $Forename; ?></td></tr>
<tr><td>Date of Birth</td> <td><?php echo $DateofBirth; ?></td></tr>
<tr><td>UTR</td> <td><?php echo $UTR; ?></td>
</tr>
<tr><td>NINO</td> <td><?php echo $NINO; ?></td>
</tr>
<tr><td>Address</td> <td><?php echo $Address; ?></td></tr>
<tr><td>Postcode</td> <td><?php echo $Postcode; ?></td></tr>
<tr><td>AddressAffectiveFrom</td> <td><?php echo $AddressAffectiveFrom; ?></td></tr>
<tr><td>Mobile</td> <td><?php echo $Mobile; ?></td></tr>
<tr><td>Landline</td> <td><?php echo $Landline; ?></td></tr>
<tr><td>Email</td> <td><?php echo $Email; ?></td></tr>
<tr><td>Balance</td> <td><?php echo $Balance; ?></td></tr>
</table>
</body>
</html>
这是更新代码
<?php
$RecordReference = $_POST['RecordReference'];
$date = date('d/m/Y h:i:s', time());
$Status = $_POST['Status'];
$AgentName = $_POST['AgentName'];
$ReturnFiledOn = $_POST['DateReturnFiled'];
$InfoOnline = $_POST['Online'];
$Surname = $_POST['Surname'];
$Forename =$_POST['Forename'];
$DateofBirth = $_POST['DateofBirth'];
$UTR = $_POST['UTR'];
$NINO = $_POST['NINO'];
$Address = $_POST['Address'];
$Postcode = $_POST['Postcode'];
$AddressAffectiveFrom = $_POST['AddressAffectiveFrom'];
$Mobile = $_POST['Mobile'];
$Landline = $_POST['Landline'];
$Email = $_POST['Email'];
$Balance = $_POST['Balance'];
// Connect to the database
require_once "config.php";
// update data in mysqli database
$sql = ("UPDATE selfemployed SET RecordReference = '$RecordReference', Dateofrecordcreation = '$date', Status = '$Status', AgentName = '$AgentName', ReturnFiledOn = '$ReturnFiledOn', InfoOnline = '$InfoOnline', Surname = '$Surname', Forename = '$Forename', DateofBirth = '$DateofBirth', UTR = '$UTR', NINO = '$NINO', Address = '$Address', Postcode = '$Postcode', AddressAffectiveFrom = '$AddressAffectiveFrom', Mobile = '$Mobile', Landline = '$Landline', Email = '$Email', Balance = '$Balance' WHERE RecordReference = '$RecordReference'");
// Close our connection to the database
mysqli_close($connection);
?>
<script type="text/javascript">
window.history.go(-2);
</script>
任何帮助这是非常感谢,因为我在什么是错误的茫然。
3条答案
按热度按时间9cbw7uwe1#
结果是,当我把所有的东西放在一个页面上时,我所需要做的就是将update按钮id和名称从update改为update,然后就完美地工作了。
llycmphe2#
请尝试使用准备好的语句(mysqli stmts或pdos)来避免sql注入。
bq3bfh9z3#
您从未运行过更新查询,请按以下方式运行更新查询