Jump to content


Photo

php bug mysql Syntax error??


  • Please log in to reply
10 replies to this topic

#1 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 09 October 2006 - 09:39 PM

The attached file is the complete code that has been giving me a headack for the last two days. I'm thinking that there is a syntax error some where.

the code works on my local server but does not on my web server. 

The code will display ther tabel header and seems to end after that. This is confirmed as it does not include my menu bar which in loaded via 'include "leftlinks";. 

any help or throughts why this is not working is great


thank you
Kevin

[attachment deleted by admin]

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 09 October 2006 - 09:41 PM

You will get alot quicker and more responses if you just post the code.

#3 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 09 October 2006 - 09:45 PM

If you're sure it's an error in your SQL statement, why not just post the statement?
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#4 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 09 October 2006 - 10:07 PM

because of the size I thought that it would be easier to post a file

<?php
		
include 'db.php'; 

$user_id = $_SESSION['user_id'];
echo $owner_id; 

//-Owner Profile--------------------------------------------------------------------------------------

$ownerQuery = "SELECT * FROM users WHERE user_id = '$owner_id'";

$ownerResult = mysql_query($ownerQuery)or die("Get Search results Error: ".mysql_error()); 

while($ownerR = mysql_fetch_assoc($ownerResult)) { 


$firstname = $ownerR['first_name'];
$lastname = $ownerR['last_name'];
$street_address = $ownerR['street_address'];
$post_office_box = $ownerR['post_office_box'];
$city = $ownerR['city'];
$province = $ownerR['province'];
$postal = $ownerR['postal'];
$home_phone = $ownerR['home_phone'];
$email_address = $ownerR['email_address'];
$dob = $ownerR['DOB'];
$spousefirstname = $ownerR['spousefirstname'];
$spouselastname = $ownerR['spouselastname'];

$currentDate = date('Y-m-d');

$age = floor(dateDiff("-", date("Y-m-d"), $dob)/365); 

// Owner Table
echo"<table class='displayinfo'>";
echo"<tr>";
echo"<th class='displayhead' colspan='4'>Profile Owner</th><br>";
echo"</tr>";

echo"<tr class='blue'>";
echo"<td class='width'><b>First Name</b></td>";
echo"<td class='adjacent'><b>Last Name</b></td>";
echo"<td class='adjacent'><b>Date of Birth</b></td>";
echo"<td class='adjacent'><b>Age</b></td>";
echo"</tr>";

   
   echo "<tr class='blue'>"; 
   echo "<td class='width'>$firstname</td>"; 
   echo "<td class='adjacent'>$lastname</td>"; 
   echo "<td class='adjacent'>$dob</td>"; 
   echo "<td class='adjacent'>$age</td>"; 
   echo "</tr>" ;
} 
echo "</table>"; 
echo "<br>";


//-------------------Spouses Information-----------------------

if($spousefirstname =="" and $spouselastname =="") {

}else{

$spouseQuery = "SELECT * FROM users WHERE user_id = '$owner_id'";

$spouseResult = mysql_query($spouseQuery)or die("Get Search results Error: ".mysql_error()); 

echo"<table class='displayinfo'>";
echo"<tr>";
echo"<th class='displayhead' colspan='5'>Spouse</th><br>";
echo"</tr>";

echo"<tr>";
echo"<td class='width'><b>First / Last Name</b></td>";
echo"<td class='adjacent'><b>Date of Birth</b></td>";
echo"<td class='adjacent'><b>Age</b></td>";
echo"<td class='adjacent'><b>Email</b></td>";
echo"<td class='adjacent'><b>Photos</b></td>";
echo"</tr>";

while($spouseR = mysql_fetch_assoc($spouseResult)) { 

$spousefirstname = $spouseR['spousefirstname'];
$spouselastname = $SpouseR['spouselastname'];
$spousedob = $spouseR['spousedob'];

$currentDate = date('Y-m-d');


if(spousedob != ""){
$spouseage = floor(dateDiff("-", date("Y-m-d"), $spousedob)/365); 

}else{

}
 
 //Check If spouse is a registered user, if so offer link to view thier family profile if not display spouses name only
 $spouse_check = mysql_query("SELECT * FROM users WHERE first_name ='$spousefirstname' AND last_name='$spouselastname' AND DOB = '$spousedob'")or die("Get spouse check Error: ".mysql_error());

  $spouseS=mysql_fetch_assoc($spouse_check);
   
  $new_id = $spouseS['user_id'];
  $spouseEmail = $spouseS['email_address'];
  
  $spouse_find = mysql_num_rows($spouse_check);

 if(($spouse_find) == 1) {

 $spousePerson = "<a href='SearchDetails.php?owner_id=$new_id'>$spousefirstname $spouselastname</a>";
}else{

$spousePerson = $spousefirstname.' ' .$spouselastname;
} 

	// check if there found user has a photo ablum
	$spousePhotoCheck = mysql_query("SELECT * FROM images WHERE owner_id = '$new_id'")or die("Spouse Photo Error: ".mysql_error());
	$sousePhoto_find = mysql_num_rows($spousePhotoCheck);
	
   echo "<tr>"; 
   echo "<td class='width'>$spousePerson</td>"; ; 
   echo "<td class='adjacent'>$spousedob</td>"; 
   echo "<td class='adjacent'>$spouseage</td>";
   
   // add link if email address found
   if($spouseEmail!=""){
   echo "<td class='adjacent'><a class='emailBullet' href='sendEmail.php?email=$spouseEmail'><img src='images/bemail.gif' alt='emalBullet'></a></td>";  
     }else{
   echo "<td class='adjacent'></td>";
   }
   // add link if user has 
      if($spousePhoto_find >0){
   echo "<td class='adjacent'><a class='emailBullet' href='photos/usersPhotoAlbum.php?owner_id=$new_id'><img src='images/camera.jpg' alt='cameraBullet'></a></td>";  
     }else{
   echo "<td class='adjacent'> </td>";
   }
   echo "</tr>" ;
} 
echo "</table>"; 
echo "<br>";
} //end spouse data checkS
////---------------------Childrens Information---------------------

$childQuery = "SELECT * FROM Links L, children C WHERE L.User_id = '$owner_id' AND C.child_id = L.child_id";

$childResult = mysql_query($childQuery)or die("Child Search Error: ".mysql_error()); 

if(mysql_num_rows($childResult) < 1) { // check if data found

}else{ // closing else and end

echo"<table class='displayinfo'>";
echo"<tr>";
echo"<th class='displayhead' colspan='5'>Children</th><br>";
echo"</tr>";
echo"<tr class='blue'>";
echo"<td class='width'><b>First / Last Name</b></td>";
echo"<td class='adjacent'><b>Date of Birth</b></td>";
echo"<td class='adjacent'><b>Age</b></td>";
echo"<td class='adjacent'><b>Email</b></td>";
echo"<td class='adjacent'><b>Photos</b></td>";
echo"</tr>";

while($childR = mysql_fetch_assoc($childResult)) { 

$childfirstname = $childR['childfirstname'];
$childlastname = $childR['childlastname'];
$childdob = $childR['childdob'];

if(childdob != ""){

$currentDate = date('Y-m-d');
$childage = floor(dateDiff("-", date("Y-m-d"), $childdob)/365);
}else{

}

//Check If child is a registered user, if so offer link to view thier family profile if not display childs name only
 $child_check = mysql_query("SELECT * FROM users WHERE first_name ='$childfirstname' AND last_name='$childlastname' AND DOB = '$childdob'")or die("Child Registered Error: ".mysql_error());

  $childS = mysql_fetch_assoc($child_check);
   
  $new_id = $childS['user_id'];
  $childEmail = $childS['email_address'];
 
  $child_find = mysql_num_rows($child_check);

 if(($child_find) == 1) {

 $childPerson = "<a href='SearchDetails.php?owner_id=$new_id'>$childfirstname $childlastname</a>";
}else{

$childPerson = $childfirstname.' ' .$childlastname;
}

	$childPhotoCheck = mysql_query("SELECT * FROM images WHERE owner_id = '$new_id'")or die("Child PhotoCheck Error: ".mysql_error());
	$childPhoto_find = mysql_num_rows($childPhotoCheck);
   
   echo "<tr>"; 
   echo "<td class='width'>$childPerson</td>"; 
   echo "<td class='adjacent'>$childdob</td>"; 
   echo "<td class='adjacent'>$childage</td>";
   if($childEmail!="") {
   echo "<td class='adjacent'><a class='emailBullet' href='sendEmail.php?email=$childEmail'><img   	  src='images/bemail.gif' alt='emalBullet'></a></td>"; 
   }else{
   echo "<td class='adjacent'></td>";
   }
   
      // add link if user has 
      if($childPhoto_find >0){
   echo "<td class='adjacent'><a class='emailBullet' href='photos/usersPhotoAlbum.php?owner_id=$new_id'><img src='images/camera.jpg' alt='cameraBullet'></a></td>";  
     }else{
   echo "<td class='adjacent'></td>";
   }
   echo "</tr>";
} 
echo "</table>"; 
echo "<br>";
} //end $result check

//-----------------------------Parents Information------------------------
$parentQuery = "SELECT * FROM Links L, parent C WHERE L.User_id = '$owner_id' AND C.parent_id = L.parent_id";

$parentResult = mysql_query($parentQuery)or die("Get Search results Error: ".mysql_error()); 

if(mysql_num_rows($parentResult) < 1) { // check if data found

}else{ // closing else and end

echo"<table class='displayinfo'>";
echo"<tr>";
echo"<th class='displayhead' colspan='5'>Parents</th><br>";
echo"</tr>";
echo"<tr class='blue'>";
echo"<td class='width'><b>First / Last Name</b></td>";
echo"<td class='adjacent'><b>Date of Birth</b></td>";
echo"<td class='adjacent'><b>Age</b></td>";
echo"<td class='adjacent'><b>Email</b></td>";
echo"<td class='adjacent'><b>Photos</b></td>";
echo"</tr>";

while($parentR = mysql_fetch_assoc($ParentResult)) { 

$parentfirstname = $parentR['parentfirstname'];
$parentlastname = $parentR['parentlastname'];
$parentdob = $parentR['parentdob'];

$currentDate = date('Y-m-d');

if(parentdob != ""){

$parentage = floor(dateDiff("-", date("Y-m-d"), $parentdob)/365);
}else{

}

/*// check if there found user has a photo ablum
	$photoCheck = mysql_query("SELECT * FROM images WHERE owner_id = '$new_id'");
	$photo_find = mysql_num_rows($photoCheck);*/

//Check If parent is a registered user, if so offer link to view thier family profile if not display parents name only
 $parent_check = mysql_query("SELECT * FROM users WHERE first_name ='$parentfirstname' AND last_name='$parentlastname' AND DOB = '$parentdob'")or die("Parent Register Check Error: ".mysql_error()); ;

  $s=mysql_fetch_assoc($parent_check); 
   
  $new_id = $s['user_id'];
  $parentEmail = $s['email_address'];
  
  $parent_find = mysql_num_rows($parent_check);

 if(($parent_find) == 1) {

 $parentPerson = "<a href='SearchDetails.php?owner_id=$new_id'>$parentfirstname $parentlastname</a>";
}else{

$parentPerson = $parentfirstname.' ' .$parentlastname;
}
   // check if there found user has a photo ablum
	$parentPhotoCheck = mysql_query("SELECT * FROM images WHERE owner_id = '$new_id'")or die("Parent Photo Check Error: ".mysql_error());
	$parentPhoto_find = mysql_num_rows($parnetPhotoCheck);
	
   echo "<tr>"; 
   echo "<td class='width'>$parentPerson</td>"; 
   echo "<td class='adjacent'>$parentdob</td>"; 
   echo "<td class='adjacent'>$parentage</td>";  
   if($parentEmail!=""){
   
   echo "<td class='adjacent'><a class='emailBullet' href='sendEmail.php?email=$parentEmail'><img src='images/bemail.gif' alt='emalBullet'></a></td>"; 
        }else{
   echo "<td class='adjacent'></td>";
   }
   
      // add link if user has 
      if($parentPhoto_find >0){
   echo "<td class='adjacent'><a class='emailBullet' href='photos/usersPhotoAlbum.php?owner_id=$new_id'><img src='images/camera.jpg' alt='cameraBullet'></a></td>";  
     }else{
   echo "<td class='adjacent'></td>";
   }
   echo "</tr>" ;
} 
echo "</table>"; 
echo "<br>";
} //end $result check

//-----------------------------siblings Information------------------------
$siblingQuery = "SELECT * FROM Links L, sibling C WHERE L.User_id = '$owner_id' AND C.sibling_id = L.sibling_id";

$siblingResult = mysql_query($siblingQuery)or die("Get Search results Error: ".mysql_error()); 

if(mysql_num_rows($siblingResult) < 1) { // check if data found

}else{ // closing else and end

echo"<table class='displayinfo'>";
echo"<tr>";
echo"<th class='displayhead' colspan='5'>siblings</th><br>";
echo"</tr>";
echo"<tr class='blue'>";
echo"<td class='width'><b>First / Last Name</b></td>";
echo"<td class='adjacent'><b>Date of Birth</b></td>";
echo"<td class='adjacent'><b>Age</b></td>";
echo"<td class='adjacent'><b>Email</b></td>";
echo"<td class='adjacent'><b>Photos</b></td>";
echo"</tr>";

while($siblingR = mysql_fetch_assoc($siblingResult)){ 

$siblingfirstname = $siblingR ['siblingfirstname'];
$siblinglastname = $siblingR['siblinglastname'];
$siblingdob = $siblingR['siblingdob'];

$currentDate = date('Y-m-d');

if(siblingdob != ""){

$siblingage = floor(dateDiff("-", date("Y-m-d"), $siblingdob)/365);
}else{

}

// check if there found user has a photo ablum
	$siblingPhotoCheck = mysql_query("SELECT * FROM images WHERE owner_id = '$new_id'")or die("Sibling Photo Error: ".mysql_error());
	$siblingPhoto_find = mysql_num_rows($siblingPhotoCheck);

//Check If sibling is a registered user, if so offer link to view thier family profile if not display siblings name only
 $sibling_check = mysql_query("SELECT * FROM users WHERE first_name ='$siblingfirstname' AND last_name='$siblinglastname' AND DOB = '$siblingdob'")or die("Sibling Registered User Error: ".mysql_error()); ;

  $siblingS=mysql_fetch_assoc($sibling_check); 
   
  $new_id = $siblingS['user_id'];
  $siblingEmail = $sinblingS['email_address'];
  
  $sibling_find = mysql_num_rows($sibling_check);

 if(($sibling_find) == 1) {

 $siblingPerson = "<a href='SearchDetails.php?owner_id=$new_id'>$siblingfirstname $siblinglastname</a>";
}else{

$siblingPerson = $siblingfirstname.' ' .$siblinglastname;
}
/*   // check if user has a photo ablum
	$photoCheck = mysql_query("SELECT * FROM images WHERE owner_id = '$new_id'")or die("Get Sibling Photo Error: ".mysql_error()); ;
	$photo_find = mysql_num_rows($photoCheck);*/
	
   echo "<tr>"; 
   echo "<td class='width'>$siblingPerson</td>"; 
   echo "<td class='adjacent'>$siblingdob</td>"; 
   echo "<td class='adjacent'>$siblingage</td>";  
   if($siblingEmail!=""){
   
   echo "<td class='adjacent'><a class='emailBullet' href='sendEmail.php?email=$siblingEmail'><img src='images/bemail.gif' alt='emalBullet'></a></td>"; 
        }else{
   echo "<td class='adjacent'></td>";
   }
   
      // add link if user has 
      if($siblingPhoto_find >0){
   echo "<td class='adjacent'><a class='emailBullet' href='photos/usersPhotoAlbum.php?owner_id=$new_id'><img src='images/camera.jpg' alt='cameraBullet'></a></td>";  
     }else{
   echo "<td class='adjacent'></td>";
   }
   echo "</tr>" ;
} 
echo "</table>"; 
echo "<br>";
} //end $result check

?>





#5 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 10 October 2006 - 02:09 AM

Hi,

I changed code to show where I'm currently at

#6 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 10 October 2006 - 02:47 AM

If it helps here is the info to loggin to my webpage and see what the code is doing.


familyclick.ca

Click the family details menu option.  There is information setup of this user that should be dispayed.

username: testUser
password: f40h4tt6

#7 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 10 October 2006 - 03:06 AM

Try including the sql statement in your die(), like this:

$sql = "SELECT * FROM table";
mysql_query($sql) or die( 'Error executing $sql ' . mysql_error());


#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 October 2006 - 10:40 AM

Try including the sql statement in your die(), like this:

$sql = "SELECT * FROM table";
mysql_query($sql) or die( 'Error executing $sql ' . mysql_error());


Use double quotes btherl. Variables will not work in single quotes. Try this instead:

$sql = "SELECT * FROM table";
mysql_query($sql) or die( "Error executing query: {$sql}<br />\n" . mysql_error());


#9 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 11 October 2006 - 01:58 AM

Not shure what you mean, it appears that the order of my code is the issue, this is blowing my mind. I had everything working great on my test server (XAMPP) and when I uploaded my webpage to my webhosting company(Domain Direct) this is when everything stoped working properly.

#10 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 11 October 2006 - 05:20 PM

Try placing simple echo statements after each of your sql queries and then tell us when and where it blows up.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#11 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 11 October 2006 - 09:33 PM

did you switch variable names in these statements:
$user_id = $_SESSION['user_id'];
echo $owner_id;

$owner_id is not defined but is used in the sql below instead of $user_id which you meant I think




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users