简体   繁体   中英

Not getting data from MySQL - PHP

I'll start off with the code:

$permission = $_SESSION['permission'];
// Connect to database
$con = new mysqli("localhost", "privateinfo", "privateinfo", "privateinfo");

// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Prepare to select all liabilities
$stmt = $con->prepare("SELECT `Linking`, `Edit_Liab`, `Own_Stud`, `All_Stud`, `View_Report`, `Read_Write` FROM Permissions WHERE `ID`=?");
$stmt->bind_param("s", $permission);  // Bind variables to the result of the query
$stmt->execute(); // Execute the query
$stmt->bind_result($linking, $editliab, $ownstud, $allstud, $viewrep, $readwrite); // Bind variables to the result of the query
$stmt->store_result();
$stmt->close();

Basically, my problem is that php isn't getting any variables. All variables coming in are supposed to be 1, but they're all actually zero. The connection is fine, and I tried putting die statements on literally everything to come up with an error, but nothing came up. The permission variable going in is set properly too. Putting it directly in as SQL code comes up with the right responses too. I'm not too sure what's wrong here. Anyone have any idea?

You need to fetch a row instead of storing the result .

So change:

$stmt->store_result();

to:

$stmt->fetch();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM