Jump to content

Archived

This topic is now archived and is closed to further replies.

proctk

php bug mysql Syntax error??

Recommended Posts

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]

Share this post


Link to post
Share on other sites
You will get alot quicker and more responses if you just post the code.

Share this post


Link to post
Share on other sites
If you're sure it's an error in your SQL statement, why not just post the statement?

Share this post


Link to post
Share on other sites
because of the size I thought that it would be easier to post a file

[code=php:0]
<?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

?>



[/code]

Share this post


Link to post
Share on other sites
If it helps here is the info to loggin to my webpage and see what the code is doing.


[URL=http://www.familyclick.ca]familyclick.ca[/URL]

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

username: testUser
password: f40h4tt6

Share this post


Link to post
Share on other sites
Try including the sql statement in your die(), like this:

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

Share this post


Link to post
Share on other sites
[quote author=btherl link=topic=111002.msg449617#msg449617 date=1160449587]
Try including the sql statement in your die(), like this:

[code]$sql = "SELECT * FROM table";
mysql_query($sql) or die( 'Error executing $sql ' . mysql_error());[/code]
[/quote]

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Try placing simple echo statements after each of your sql queries and then tell us when and where it blows up.

Share this post


Link to post
Share on other sites
did you switch variable names in these statements:
[code]$user_id = $_SESSION['user_id'];
echo $owner_id; [/code]
$owner_id is not defined but is used in the sql below instead of $user_id which you meant I think

Share this post


Link to post
Share on other sites

×

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.