Jump to content

Using $_SESSION variable in SQL Statement


jackh

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">
					<tr>
					<th>ID</th>
					<th>Vehicle ID</th>			
					
					<?php
									
						while($custveh = mysqli_fetch_assoc($row)){
							echo "<tr>";					
							echo "<td>".$custveh['id']."</td>";					
							echo "<td>".$custveh['vehID']."</td>";					
							echo "</tr>";
						}
					
					?>					
				</table>	

Any suggestions would be great, thanks!

Jack

Link to comment
Share on other sites

Print out the value of $sql to see what it's doing

I echoed the value and still wasn't working - had a look at my query and it was because I used a capital in the name! So simple.

Thanks for your help Foxy Mod! :good:

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