Francisco Loureiro Francisco Loureiro - 5 months ago 9
PHP Question

How do I delete a row in sql using php?

So, i have been trying really hard to know how to delete a row in sql. I searched a lot on the internet, but i just cant find the answer. I came here to see if anyone can help me.

also, i'm kinda new to this.

$conn = mysqli_connect("", "a26719", "sde3n13n", "aluno_a26719");

$sql = "SELECT Username, Password, UserID FROM utilizadores";
$result = mysqli_query($conn, $sql);

echo "<table border='2' style='width:100%'>";
echo "<tr><td> Username </td><td> Password </td><td> User ID </td></tr>";
if (mysqli_num_rows($result) > 0)
while($row = mysqli_fetch_assoc($result))

echo "<tr><td>" . $row["Username"]. "</td><td>" . $row["Password"]. "</td><td>". $row["UserID"]. "</td></tr>";


echo "0 results";
echo "</table>";

echo "<form action='elimina.php' method='POST'>";
echo "Username: <input type='text' name='username'><br>";
echo "<input type='submit' value='submit'>";
echo "</form>";

$sql="DELETE FROM utilizadores WHERE Username='$username'";

echo "<a href='gestao.php'>Voltar</a>";

I know the table works, but the last few lines of deleting don't.

$result = mysqli_query($conn, $sql);

The above call is what executes it in the first part of your code. You are not executing the DELETE query. You simply define a string and do nothing with it.