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

Query looks like: SELECT * FROM datakey
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in /srv/disk1/2648096/www/site/test/index.php on line 35

 

It shows the session data

Edited by Jedijon
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.