WAMFT1 Posted September 5, 2013 Share Posted September 5, 2013 I have been trying to figure this out for days but no luck so far. I have two tables which I want to pull info from and from what I read a join query is the way to go. I need to pull the info from the bank table based on the login id in the users table. I keep getting a black page result or a Data not Found result. Because this is the first time I have tried a join query I don't really know what I am doing. Is anyone able to give me some advice? <?php //if the login session does not exist therefore meaning the user is not logged in if(strcmp($_SESSION['uid'],"") == 0){ //display and error message header('Location: ../index.php'); }else{ //otherwise continue the page //this is out update script which should be used in each page to update the users online time $time = date('U')+50; $update = mysql_query("UPDATE `e-users` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); ?> <?php //make sure you close the check if their online } ?> <?php require("../edb.php"); $result = mysql_query("SELECT AcctName, BSB1, BSB2, AccNumber, Adviser, Bank FROM a-bank JOIN e-users ON a-bank.Adviser = e-users.id; WHERE e-users.id = '".$_SESSION['uid']."'"); if (!$result) { die("Error: Data not found.."); } $AcctName=$test['AcctName']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/ Share on other sites More sharing options...
kicken Posted September 5, 2013 Share Posted September 5, 2013 Since your table names have a - in them, you have to quote them with backticks (`). With out them the - will be treated as a minus and cause a syntax error. As a tip, you should not use any special characters in your table or column names. Stick with a-z, 0-9, and _. Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448225 Share on other sites More sharing options...
WAMFT1 Posted September 5, 2013 Author Share Posted September 5, 2013 I have renamed the tables to remove the possibility of any syntax error but still having problems with the page working. Any ideas, I keep getting Data not Found <?php require("../edb.php"); $result = mysql_query("SELECT AcctName, BSB1, BSB2, AccNumber, Adviser, Bank FROM abank JOIN eusers ON abank.Adviser=eusers.id; WHERE abank.Adviser = '".$_SESSION['uid']."'"); if (!$result) $AcctName=$test['AcctName']; $BSB1=$test['BSB1']; $BSB2=$test['BSB2']; $AccNumber=$test['AccNumber']; $Adviser=$test['Adviser']; $Bank=$test['Bank']; { die("Error: Data not found.."); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448229 Share on other sites More sharing options...
Yohanne Posted September 5, 2013 Share Posted September 5, 2013 SELECT abank.AcctName, abank.BSB1, abank.BSB2, abank.AccNumber, abank.Adviser, abank.Bank, eusers.id FROM abank INNER JOIN eusers ON abank.Adviser=eusers.id; WHERE abank.Adviser = '$_SESSION[uid]'"); TRY: Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448233 Share on other sites More sharing options...
gizmola Posted September 5, 2013 Share Posted September 5, 2013 Something seems to be wrong with this code: if (!$result) $AcctName=$test['AcctName']; $BSB1=$test['BSB1']; $BSB2=$test['BSB2']; $AccNumber=$test['AccNumber']; $Adviser=$test['Adviser']; $Bank=$test['Bank']; { die("Error: Data not found.."); } That isn't even syntactically correct, but assuming we're missing something, the condition is incorrect. It would be this instead: if ($result) { $AcctName=$test['AcctName']; $BSB1=$test['BSB1']; $BSB2=$test['BSB2']; $AccNumber=$test['AccNumber']; $Adviser=$test['Adviser']; $Bank=$test['Bank']; } else { die("Error: Data not found.."); } Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448237 Share on other sites More sharing options...
WAMFT1 Posted September 5, 2013 Author Share Posted September 5, 2013 I am still getting the Data Not Found. Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448238 Share on other sites More sharing options...
Solution WAMFT1 Posted September 5, 2013 Author Solution Share Posted September 5, 2013 Hi Everyone, I decided to go another way with this. It was getting to difficult and frustrating. Thanks for your input! Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448242 Share on other sites More sharing options...
mac_gyver Posted September 6, 2013 Share Posted September 6, 2013 i have marked this thread solved for you to help prevent others from spending time trying to fix things in an abandoned thread. as stated in the thread you started after this one, the following logic does not mean that data was not found, it means the the query failed with an error of some kind - if (!$result) { die("Error: Data not found.."); } using your database library's error reporting function (mysql_error() in this case) would have pointed to the part of the query where mysql found a problem. Quote Link to comment https://forums.phpfreaks.com/topic/281870-inner-join-issues-first-time-i-have-tried/#findComment-1448392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.