Get info from 1 table to look for another table

Im trying to have my site access a table look at the location where member is from then go and look for the table that matchs that heres what iv got.

[php]$tbl_name=$test[‘location’]; // Table name

$query = “SELECT * FROM members WHERE username=’{$_SESSION[‘myusername’]}’” or die($mysqli->error.LINE); //check for usernames location

$userid = $mysqli->query($query) or die($mysqli->error.__LINE__);

while($test = mysqli_fetch_assoc($userid)){
;

$sql=“SELECT * FROM $tbl_name” or die($mysqli->error.LINE); //to look for users database to post inventory
$result = $mysqli->query($sql) or die($mysqli->error.LINE);
;

while($rows=mysqli_fetch_assoc($result)){

;
} }
mysqli_close($mysqli);[/php]

And this is the error im gettings

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ at line 143 (there is no line 143 only gose to 95 lines.)

Please help :smiley:

You can’t “or die” on a string, I would also change to parameterized queries as it’s safe from sql injection

your error is probably here:
[php]username=’{$_SESSION[‘myusername’]}’"[/php]

You can see how to do this here
http://php.net/manual/en/mysqli.prepare.php

so far that’s the only way I have been able to get it to look for the username in the database, what im working on at the moment is to have Everything run into 3pages

going from looks for username in the database that’s logged in and the way its set up was the only way I was able to get it to work properly then select location of that user so now I have multiple people using the same webpage with only 1 html link but its all based on that location if you location say is Vancouver your new desination will be Vancouver.php but if your from Kelowna your desination will be Kelowna.php all coming from the same link that I set up something like this

[php]<a href="<?php echo $test['location']; ?>.php><?php echo $test['location'];?> [/php]

I was kinda shocked that it worked since iv never tried that before lol,
but only way to get it to work was the set up I have now, now im trying to get everyone instead of using
the link they all click on the one link and it just brings up there information so that will lower my website down from 30pages to 3 pages

Login page
Members section page
Data Location page

compaired to

Login page
Members section page
data location page (Kelowna)
data location page (vancover)
etc…

So now all I have to do is fix that one db_table=$test[‘location’] Works every where else but as soon as I have it look in the database again in screws up so I don’t know if this way would work better

[php]<a href="<?php echo $test['location']; ?>.php?location=<?php echo $test['location'] ?>><?php echo $test['location'];?> [/php]
then on the next page have it
[php]$db_table = $GET_[location];[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service