Jump to content

How to make it insert info from session


Jedijon

Recommended Posts

<?php
$con=mysqli_connect("IP","Username","Password","Database name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM {$_SESSION['datakey']}"; 

echo "<table border='1'>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['column1'] . "</td>";
echo "<td>" . $row['column2'] . "</td>";
echo "<td>" . $row['column3'] . "</td>";
echo "<td>" . $row['column4'] . "</td>";
echo "<td>" . $row['column5'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

Link to comment
Share on other sites

I have that 

<?php
// Initialize the session
session_start();
 
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
    header("location: ../login");
    exit;
}
?>

Link to comment
Share on other sites

You should write query statements into a variable to make it easier to debug should you need to, as in this case.

	$q = "SELECT * FROM {$_SESSION['datakey']}"; 
	echo "Query looks like: $q";
	 $results = mysqli_query($con, $q);
	

Run this code and look at the actual query you created to ensure that your assumptions are correct.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.