Jump to content

Recommended Posts

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;
}

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337833
Share on other sites

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 ^ ?

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337836
Share on other sites

$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!

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337839
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337919
Share on other sites

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;
}
}

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337923
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337936
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/67338-solved-query-problem/#findComment-337943
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.