Reputation: 107
Here is the code
<?
$x=$_SESSION["name"];
mysqli_query($mysqli, "DELETE from Uzivatel WHERE username='$x'");
mysqli_close($mysqli);
header("Location: index.php");
?>
I saved username into $_SESSION["name"]
at the previous page. Here I just load it into $x
and I want to delete row from database where username = $x
but I can't and I don't know why.
If I change $x
in the SQL command into normal string name like Hed (for example) it will delete him. But if I want to delete it through variable, nothing happens.
And yes I checked if the username is in the $_SESSION["name"]
through echo, and yes it's there.
Upvotes: 1
Views: 142
Reputation: 1693
You should start the session before you can use a SESSION variable:
<?php
session_start();
$x=$_SESSION["name"];
mysqli_query($mysqli, "DELETE from Uzivatel WHERE username='$x'");
mysqli_close($mysqli);
header("Location: index.php");
?>
Upvotes: 2