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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...