How to delete row in MySQL table whereby PHP HTML form

Hi Everyone,
MySQL table nemed “test” is onsisted of 2 fields as shown at the 1 st screenshot hereby:
The above table contains 4 rows as shown at thescreenshot above.

My php code uploads a table that browses the above table’s rows. At the end of each row in the PHP page there is
a “submit button” to delete the current row as it shows on the2nd screenshot:
As you can see at the above screenshot, when I tap the “Delete” button I get an error that says that the delete
query is missing the “where” “counter” key.
I try to set the current row’s “counter” value but i’m afraid I dont know how to do so…
Here is the code:
[php]

<?php // to_forum.php $MyHOST = 'localhost'; $MyUSER = 'yossi'; $MyPASS = 'yoss4qpines'; $MyDB = 'test'; $MyCONNECTION = NEW MYSQLI($MyHOST,$MyUSER,$MyPASS,$MyDB); IF(!$MyCONNECTION) DIE('Gevald' .MYSQLI_CONNECT_ERROR()); MYSQLI_SET_CHARSET($MyCONNECTION,'UTF8'); if (isset($_POST['delete']) && isset($_POST['MyCOUNTER'])) { $MyCOUNT = get_post($MyCONNECTION, 'MyCOUNTER'); $MyQUE = "DELETE FROM test WHERE counter = '$MyCOUNT'"; $MyRESULT = $MyCONNECTION->query($MyQUE); if (!$MyRESULT) echo "DELETE failed: $MyQUE
" . $MyCONNECTION->error . "

"; } echo <<<_END Id _END; $MyQUE = "SELECT counter, id FROM test "; $MyRESULT = $MyCONNECTION->query($MyQUE); if (!$MyRESULT) die ("Database access failed: " . $MyCONNECTION->error); $numOfRows = $MyRESULT->num_rows; echo <<<_END table, th, td {border-collapse: collapse;} th {background-color: #f1f1c1;border: 1px solid black;} td {border: 1px solid black;} IDs _END; for ($j = 0 ; $j < $numOfRows ; $j++) { $MyRESULT->data_seek($j); $row = $MyRESULT->fetch_array(MYSQLI_NUM); echo <<<_END _END; } echo "
COUNTER ID action
$row[0] $row[1]
"; $MyRESULT->close(); $MyCONNECTION->close(); function get_post($conn, $var) { return $conn->real_escape_string($_POST[$var]); } ?>

[/php]
Could anyone show me please how to set the current row’s counter value to the “Delete” query?
Thanks a lot !


to_forum1-a.gif

I’m not sure what you are trying to achieve here. The one thing I can see that stands out among the other things in that code is $myCount as a string in your delete query.

You don’t need to wrap your integer in quotes or it will be treated like a string.

Also, I don’t go into it, but your code is prone to injection. I’m sure there would be a lot of help in this forum around that very issue.

Sponsor our Newsletter | Privacy Policy | Terms of Service