Jump to content

Using $_SESSION variable in SQL Statement

Recommended Posts

Hi all,


I'm trying to execute a query which uses the value from my session which is set when the user logs in. When I try to view the query, it displays nothing.


SQL statement

// get value of session
$username = $_SESSION['username'];

// executeable query
$sql = ("SELECT * FROM custstock 
		WHERE username = '$username'");
// query
$row = mysqli_query($custdb, $sql) or die(mysqli_error($custdb));

The code for my table;

<table width="100%" border="1" cellpadding="1" cellspacing="1" class="carInfo">
					<th>Vehicle ID</th>			
						while($custveh = mysqli_fetch_assoc($row)){
							echo "<tr>";					
							echo "<td>".$custveh['id']."</td>";					
							echo "<td>".$custveh['vehID']."</td>";					
							echo "</tr>";

Any suggestions would be great, thanks!


Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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