I've made a simple form to deleting entries in a table. When I click the submit button my variables aren't populating. Could someone please suggest why? Here's the html code:
<tr class="tr">
<td class="td">2</td>
<td class="td">01/05/2017</td>
<td class="td">1152</td>
<td class="td">1270</td>
<td class="td">1125</td>
<td class="td">855</td>
<td class="td">1078</td>
<td class="td">865</td>
<td class="td">1730</td>
<td class="td">1255</td>
<td class="td">
<form action="delete.php" "method="post">
<input type="hidden" value="2" name="id">
<input type="hidden" value="zjl1nl_asia" name="region">
<input type="submit" value="Delete" class="delete_button">
</form>
</td>
</tr>
and the receiving php
<?php
function secure($var){
$var = stripslashes($var);
$var = strip_tags($var);
$var = htmlentities($var);
return $var;
}
//Connect to database
$hn = "localhost";
$db = "XXXX";
$un = "XXXX";
$pw = "XXXX";
$conn = new mysqli($hn, $un, $pw, $db);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$id = secure($_POST['id']);
$region = secure($_POST['region']);
echo "<p>id: $id<br>region: $region</p>";
$query = "DELETE FROM $region WHERE id=$id";
echo $query."<br>";
$result = $conn -> query($query);
if(!$result) die ("Error: ".$conn->error);
$conn->close();
?>
When I echo the variables to screen they show no values. Looking in the address bar however I can see for example: www.example.com/add/delete.php?id=6®ion=zjl1nl_asia
Does anyone know why the variables aren't populating?
You have a syntax error in this line of your code.
<form action="delete.php" "method="post">
Replace it with
<form action="delete.php" method="post">
Now it should work fine.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments