Delete link in table msqli

Hi guys.
i am stuck i have a page called view.php

this views a list of emails on a database

i am trying to add a delete link at the side of each email but i keep getting an error

error message
unexpected ‘href’ (T_STRING), expecting ‘,’ or ‘;’

here is the code where its going wrong …

$sqli = "SELECT * FROM data";

$result = $conn->query($sqli);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

echo "E Mail Database List <br><br>";


if($row["email"]==""){
    echo "E Mail";} else {
echo "E Mail :" .$row["email"]." 


echo "<a href="delete.php?id={$row['id']}">Delete row</a>;


<br><br>";}


}
}


$conn->close();

Take a close look to the double quotes on the last echo line. A hint: You can use double quotes and single quotes as well in php.

Download a php editor (Netbeans is free and has many features). It will highlight your code and attend you on a lot of type mistakes

i have done this now but my link will not delete. When i select delete link nothing happens.

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

{
$id = $_GET['id'];
// sqli to delete a record
$sqli = "DELETE FROM users WHERE id='$id'"; 
}

$conn->close();

You aren’t executing the SQL.

yoursite.com?id=%27%20OR%201=1

I just dropped your user table…

1 Like

sorry what ? Dropped table ?

Without using prepared statements, that url example would delete everything in the table

Sponsor our Newsletter | Privacy Policy | Terms of Service