SirChick Posted August 30, 2007 Share Posted August 30, 2007 I dont know why but i cannot get my query to work... it just say's "ID not found" but its using the session to find the ID so it must be a syntax issue but i cannot see where it is. Can you see the problem ? : $FindHouseRents = mysql_query("SELECT * FROM houses.*, userregistration.* FROM houses, userregistration WHERE houses.HouseID ='{$row['HouseID']}' userregistration.UserID='{$_SESSION['Current_User']}'"); // Fetch the row from the database if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { echo "ID not found!"; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/ Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 You have errors in your SQL, which you'd see if you had debugging or error checking. Try this: <?php $sql = 'SELECT houses.*, userregistration.* FROM houses, userregistration WHERE houses.HouseID ='.$row['HouseID'].' AND userregistration.UserID='.$_SESSION['Current_User']; //Do print $sql; here to preview your query. your first on has a TON of errors. $FindHouseRents = mysql_query($sql) OR die(mysql_error().' with query: '.$sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337833 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 This is what im getting : Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\homeloginvariables.php on line 145 ID not found! Relating to this for some reason :S // Fetch the row from the database if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { echo "ID not found!"; exit; I don't see the mistake there though ^ ? Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337836 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Did you get any errors? Post the new code including the SQL and query code. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337837 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 $sql = 'SELECT houses.*, userregistration.* FROM houses, userregistration WHERE houses.HouseID ='.$row['HouseID'].' AND userregistration.UserID='.$_SESSION['Current_User']; //Do print $sql; here to preview your query. your first on has a TON of errors. $FindHouseRents = mysql_query($sql) OR die(mysql_error().' with query: '.$sql); } // Fetch the row from the database if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { echo "ID not found!"; exit; } All that returns was : Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\homeloginvariables.php on line 145 ID not found! Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337839 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 What's with the closing bracket after your mysql_query line? If it's within a conditional statement it's probably not being run. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337840 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 oh sos thats cos its in an If its right end of it though Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337857 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Yeah, but the next part of the code isn't. So it looks like it's not entering the IF. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337861 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 Ok this is all of it (sorry for the delay) just had to do a quick emergency on a security thing! Code: // Fetch the row from the database If (!($houserow = mysql_fetch_assoc($GetHouseInfo))) { $sql = 'SELECT houses.*, userregistration.* FROM houses, userregistration WHERE houses.HouseID ='.$row['HouseID'].' AND userregistration.UserID='.$_SESSION['Current_User']; //Do print $sql; here to preview your query. your first on has a TON of errors. $FindHouseRents = mysql_query($sql) OR die(mysql_error().' with query: '.$sql); } // Fetch the row from the database if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { echo "ID not found!"; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337919 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Yeah, but the next part of the code isn't. So it looks like it's not entering the IF. Why don't you move the rest of the related code INTO that if? Then you won't get this error. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337920 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 So you mean: // Fetch the row from the database If (!($houserow = mysql_fetch_assoc($GetHouseInfo))) { $sql = 'SELECT houses.*, userregistration.* FROM houses, userregistration WHERE houses.HouseID ='.$row['HouseID'].' AND userregistration.UserID='.$_SESSION['Current_User']; //Do print $sql; here to preview your query. your first on has a TON of errors. $FindHouseRents = mysql_query($sql) OR die(mysql_error().' with query: '.$sql); // Fetch the row from the database if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { echo "ID not found!"; exit; } } Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337923 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Yes... Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337927 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 Ok although it makes sense how come if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { wont work outside the if cos surely $FindHouseRents still passes through? Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337931 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 How could it? If you define a variable inside of a conditional statement, and the statement is never entered, the variable isn't defined. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337932 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 Well i thought that the variable was set here: $FindHouseRents = mysql_query($sql) OR die(mysql_error().' with query: '.$sql); and then at any time in the script i could of done : if (!($secondrow = mysql_fetch_assoc($FindHouseRents))) { etc or do other stuff with $FindHouseRents variable etc. wldnt of thought it need to be in the main if. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337936 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 If you define a variable inside of a conditional statement, and the statement is never entered, the variable isn't defined. Your code was in two different conditional statements. Look. Write this code: <?php $x = 1; $y = 0; if($x==2){ $y = 5; } if($x==1){ print $y; } ?> You can read it and see that $y will be == 0, NOT 5. Now, if you never define $y, you'll either get an error or nothing, depending on your settings. <?php $x = 1; if($x==2){ $y = 5; } if($x==1){ // y doesn't exist! print $y; } ?> This is similar to what you were doing, as far as I can tell. Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337943 Share on other sites More sharing options...
SirChick Posted August 30, 2007 Author Share Posted August 30, 2007 oh right that does make more sense now! thanks jesi Wasnt doubting you.. just interested in these things as im still learning Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337953 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 No problem. Anytime you can't get something to work just simplify it till it does work and you'll find your problem Quote Link to comment https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337956 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.