Jump to content


Photo

Information not pulling from database


  • Please log in to reply
9 replies to this topic

#1 Crashdowngurl

Crashdowngurl
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 May 2006 - 06:58 PM

I've been working on this for hours and I can't find whats going wrong to save my life. I have a feeling this is one of those situations where I am going to feel dumb for not realizing the problem :) I know this is probably something to do with $_GET['id'] but I am unsure how to structure it.

I am creating a page that will pull entries from a database and display a list of the enteries on the side of the page, when you click on one, it will display that entry's data. I am working doing this for my portfolio pieces for school, so each of my projects has a name that is supposed to call the id, title, type, image, description, and link from the database.

The list of entries displays perfectly on the side, however, when I click on the them, no information all appears. I've attached the code below. Please help me!



<?php
error_reporting(0);

include $_Server['DOCUMENT_ROOT'].'includes/header.html';

require('includes/database.php');                 




// What are we looking for? (Decide Query) 
$query        =    "UPDATE fbnet_portfolio WHERE id=1 SET count = count + 1"; 
    // Store info in debug 
    $debuginfo    .=    "COUNTER QUERY ".$query;   $debugtotal=$debugtotal+1; 

// Update the counter table setting the total hits up by one 
mysql_query($query,$db);                         





if (!isset($type) or $type=="") 
{ 
    $type="website"; 
} 
// Format if $id is not set or if it ="" then set it to "1" 
if (!isset($id) or $id=="") 
{ 
    $id="1";  
} 



$result = mysql_query("SELECT id, title, type FROM portfolio WHERE type='website'"); 
while($result && list($id, $title, $type)=mysql_fetch_row($result)) 
{ 
    $portfoliolist    .=    "<a href=\"webdesign.php?id=" . $id . "\">" . $title . "</a><br />"; 
} 

// What are we looking for? (Decide Query) 
$query        =    "SELECT * FROM portfolio WHERE id=".$id; 
    // Store info in debug 
    $debuginfo    .=    "INFO QUERY ".$query;   $debugtotal=$debugtotal+1; 
$result = mysql_query($query); 

//while ($myrow = mysql_fetch_row($result)) 
if ($myrow = @mysql_fetch_array($result)) 
{ 

    $title        =    $myrow[1]; 
    $type        =    $myrow[2]; 
    $image        =    $myrow[3]; 
    $description            =    $myrow[4]; 
    $link    =    $myrow[5]; 
       
} 



?>


I'm using the following to pull the information from the database:


<?PHP echo($title); ?>


Like I said, the list is working fine, it's just when you click on the links, the information relative to the id number is not displaying.

Any help with this would be EXTREMELY appreciated :)

Thank you!
-Emma

#2 thenk83

thenk83
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 May 2006 - 07:23 PM

$query        =    "SELECT * FROM portfolio WHERE id=".$id;

i think should be

$query        =    "SELECT * FROM portfolio WHERE id='$id'";

Try that out see how it works.

#3 Crashdowngurl

Crashdowngurl
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 May 2006 - 07:29 PM

still the same :(

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 02 May 2006 - 08:07 PM

I would suggest removing the error suppression ("@" symbol) to see if there are any errors with the query.

Info: PHP Manual


#5 Crashdowngurl

Crashdowngurl
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 May 2006 - 08:32 PM

[!--quoteo(post=370686:date=May 2 2006, 03:07 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 2 2006, 03:07 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I would suggest removing the error suppression ("@" symbol) to see if there are any errors with the query.
[/quote]

I removed it and the page displays no errors. Any other thoughts?

#6 thenk83

thenk83
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 May 2006 - 09:52 PM

[!--quoteo(post=370694:date=May 2 2006, 01:32 PM:name=Crashdowngurl)--][div class=\'quotetop\']QUOTE(Crashdowngurl @ May 2 2006, 01:32 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I removed it and the page displays no errors. Any other thoughts?
[/quote]

under
$result = mysql_query($query);


Try
if(!$result){ echo mysql_error(); }

That should give u a message. Hopefully!

#7 Crashdowngurl

Crashdowngurl
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 May 2006 - 10:31 PM

No message :( PHP hates me!

$query        =    "SELECT * FROM portfolio WHERE id='$id'";
    // Store info in debug 
    $debuginfo    .=    "INFO QUERY ".$query;   $debugtotal=$debugtotal+1; 
$result = mysql_query($query); 
if(!$result){ echo mysql_error(); }

Thats how I added it in there, page still displays fine, but doesn't show any of the information.

#8 ansarka

ansarka
  • Members
  • PipPipPip
  • Advanced Member
  • 128 posts
  • LocationCochin, Kerala, India

Posted 03 May 2006 - 11:59 AM

Plz change it to

// What are we looking for? (Decide Query)
$query = "SELECT * FROM portfolio WHERE id='$id'";
$result = mysql_query($query,$db);

while ($myrow = mysql_fetch_row($result))
{

$title = $myrow[1];
$type = $myrow[2];
$image = $myrow[3];
$description = $myrow[4];
$link = $myrow[5];

}

EVEN THE WORD IMPOSSIBLE IS SAYING I' M' POSSIBLE

#9 umasankar

umasankar
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 May 2006 - 01:13 PM


Hi,

First u have to check the $id value is a valued one or not.

print the value of $id. ( echo $id).

then .,

1. print the query.
2. copy the query and paste it into the PHYMYADMIN >> SQL section
( Because of first u have test the query passed is correct or not)
3.still u have problem.
4. make the query as

SELECT * FROM portfolio WHERE id='.$_GET['id'].'";


try this please.

Umasankar Subramanian

#10 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 03 May 2006 - 01:20 PM

First, as Subramanian said, $id is not even set yet. If you ar passing it thru the url, first thing at the top should be

$id = $_GET['id'];

or use Subramanian's query.

Without that you will never get anything including errors because your query is looking for a null or 0 id. This is perfectly fine for a query which is why you get no errors, and you get no results because the 0 or null id doesn't exist.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users