문제

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.

도움이 되었습니까?

해결책

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");
?> 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top