私の更新コードにいただきました!間違って把握傾ける。これは私が推測する問題を与えているコードがで、ある私はこのデータを表示するのに使用してイムコードがある
<?php
$con = mysqli_connect('localhost','root','');
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
mysqli_select_db($con,'databaseteste');
$result =mysqli_query($con,("SELECT * FROM `formando2`"));
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
echo "<table class=mainmenu border='1' width=100% >
<p><caption><h1>Registos</h1></caption></p>
<tr>
<th>Primeiro Nome</th>
<th>Ultimo Nome</th>
<th>Numero C.C</th>
<th>Numero contribuinte</th>
<th>Email</th>
<th>Morada</th>
<th>Código postal</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr><form action=update.php method=post>";
echo "<td><input type=text name=pname value='".$row['PrimeiroNome']."'></td>";
echo "<td><input type=text name=sname value='".$row['UltimoNome']."'></td>";
echo "<td><input type=text name=bi value='".$row['NumeroBI']."'></td>";
echo "<td><input type=text name=contri value='".$row['NumeroContribuinte']."'></td>";
echo "<td><input type=text name=email value='".$row['Email']."'></td>";
echo "<td><input type=text name=morada value='".$row['Morada']."'></td>";
echo "<td><input type=text name=cpostal value='".$row['CodigoPostal']."'></td>";
echo "<td><input type=hidden name=id value='".$row['idformando2']."'></td>";
echo "<td><input type=submit></td>";
echo "</tr>";
}
echo "</table>";
?>
(registos.php)更新コード。(update.phpを)
<?php
$con = mysqli_connect('localhost','root','');
if (!$con){die('Could not connect: ' . mysqli_error());}
mysqli_select_db($con,'databaseteste');
$update ="update `formando2`
set PrimeiroNome='$_POST[pname]',
UltimoNome='$_POST[sname]',
NumeroBI='$_POST[bi]',
NumeroContribuinte='$_POST[contri]',
Email='$_POST[email]',
Morada='$_POST[morada]',
CodigoPostal='$_POST[cpostal]'
where idformando2='$_POST[id]'";
if(mysqli_query($con,$update)){
header("refresh:1; url=registos.php");}
else{
printf("Error: %s\n", mysqli_error($con));
}
?>
私はそれを提出し、再びregistos.phpに続いupdate.phpをページへのに私をリダイレクトしますが、データはまだ同じです。
Registo Screen
Post update
あなたのスクリプトは[SQLインジェクション攻撃](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)の危険性があります。何が起こったのかを見てください[Little Bobby Tables](http://bobby-tables.com/)[入力を逃れている場合でも、安全ではありません!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets -around-mysql-real-escape-string)[prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)を使用してください。 –
あなたはこれらの '$ _POST'値を実際にすべて確認する努力はしません。 – RiggsFolly
@AbdullaNilamはい、フォームの最後の隠しフィールドを参照してください。 – RiggsFolly