Answer the question
In order to leave comments, you need to log in
DELETE FROM list WHERE id = 'row id in the to-do list'. How can I specify this id?
delete.php:
$id = $_GET['notesDelete']; //?
$dbc = mysqli_connect('localhost', 'root', '', 'notes')
or die('Connect error...');
$query = "DELETE FROM note WHERE id = '$id'"; //?
$result = mysqli_query($dbc, $query);
mysqli_close($dbc);
a href="delete.php?id=notesDelete=' . $row['id'] . '"><button>-</button>a //?
Answer the question
In order to leave comments, you need to log in
Error generating URL for deletion
<a href="delete.php?id=notesDelete=' . $row['id'] . '">
echo "<a href=delete.php?id=",$row['id'],"¬esDelete=1><button>delete</button></a>";
if (!isset($_GET['id'])) die("Error: not found id parameter");
$id = intval($_GET['id']);
if ($id == 0) die("Error: wrong id parameter value");
if (isset($_GET['notesDelete'])) {
$dbc = mysqli_connect('localhost', 'root', '', 'notes') or die('Connect error...');
$query = "DELETE FROM note WHERE id = ".$id;
$result = mysqli_query($dbc, $query);
mysqli_close($dbc);
} else {
die("Error: no any action found");
}
$id = intval("SELECT nothing"); var_dump($id);
$id = intval("1312; DELETE something"); var_dump($id);
$h = "DELETE FROM note WHERE id = '$id'";
var_dump($h);
$id = "10'; DROP DATABASE mysql; SELECT * FROM note WHERE id='1";
$h = "DELETE FROM note WHERE id = '$id'";
var_dump($h);
int(0)
int(1312)
string(34) "DELETE FROM note WHERE id = '1312'"
string(80) "DELETE FROM note WHERE id = '10'; DROP DATABASE mysql; SELECT * from note id='1'"
1. Prepare the query text with the prepare-function .
2. Attach the required query parameters with the bind function .
3. Execute the query with the execute function .
Request failed? View errors .
PS: In any unclear situation, read the documentation .
Let's play an evil and a good commentator, I'll be kind :) Your link is formed incorrectly - with quotes you've got it wrong. You see what kind of link is actually formed . The notesDelete parameter is passed a string' . $row['id'] . '
instead of $row['id']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question