【发布时间】:2015-09-22 13:50:28
【问题描述】:
我需要从 post call 更新插入到 MYSQL DB 中的相同数据。 这是表单代码:
<form action="salva_debiti.php" method="post">
'; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM rimanenti_mese WHERE Mese = $mese AND Anno = $anno ORDER BY cognome ASC"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo '
<table id="ricambi" style="width: 100%;" border="1">
<tr>
<td id="titolotd">Nome</td>
<td id="titolotd">Cognome</td>
<td id="titolotd">Da incassare pezzi</td>
<td id="titolotd">Da incassare benzina</td>
<td id="titolotd">Residuo '.$mese_scritto.' '.$anno_pr_div.'</td>
</tr>'; while($row = $result->fetch_assoc()) { echo '
<tr>
<td>
<input type="" name="nome[]" value="'.$nome.'">
</td>
<td>
<input type="" name="cognome[]" value="'.$cognome.'">
</td>
<td>
<input type="" name="pezzi[]" value="'.$pezzi.'">
</td>
<td>
<input type="" name="benzina[]" value="'.$benzina.'">
</td>
<td>
<input type="" name="rimanenti[]" value="'.$rimanenti.'" </td>
</tr>
' ; } echo '
<input type="submit" value="Submit">'; echo '</form>';
这是我用来插入数据的代码:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn - > connect_error) {
die("Connection failed: ".$conn - > connect_error);
}
foreach($_POST['nome'] as $nome) {
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$rimanenti_ins = $_POST['rimanenti'];
//$sql = "UPDATE rimanenti_mese SET Rimanenti='$rimanenti_ins' WHERE Nome='$nome' AND Cognome = '$cognome'";
$sql = "INSERT INTO rimanenti_mese (Nome, Cognome, Mese, Anno, Benzina, Pezzi, Rimanenti)
VALUES('$nome', '$cognome', '09', '2015', 'xxxx', 'fdfdfd', '$rimanenti_ins')
";
}
if ($conn - > query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: ".$sql.
"<br>".$conn - > error;
}
$conn - > close();
问题是它只插入最后一行... 我哪里错了?
【问题讨论】:
-
那里的注入孔不错。
-
hai risposti mi amico。如果有人解决了它,请接受答案;-)