1

My database fields are not populating but the page is confirming that it exists. So the first SQL is working, but the second is not pulling the info. If i take the page check out. It doesn't find the page and redirects to page_not_found. Am I going about this correctly? What am i doing wrong here?

//get page url and query db
$this_page = $_GET['page'];
$this_page = escape_data($_GET['page']);

//Make sure page exist
$SQL_page_exist = "SELECT page_title FROM learn_more WHERE page_title = '$this_page'";
$SPE_result = mysql_query($SQL_page_exist);
if(mysql_num_rows($SPE_result) == 0) 
{
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=page_not_found.php">';
}
else {

$SQL = 
   "SELECT  * FROM learn_more AS lm 

INNER JOIN  learn_more_to_reference_key AS lmtrk 
        ON  lm.id = lmtrk.learn_more_id 

INNER JOIN  reference_keys AS rk 
        ON  rk.keys_id = lmtrk.reference_key_id

     WHERE  page_title = '$this_page'";

$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result));
{   
        $id               =     $db_field['ID'];
        $main_title       =     $db_field['main_title'];
        $main_content     =     $db_field['main_content'];
        $reference_keys   =     $db_field['keys_href']; 
        $sub_title        =     $db_field['sub_title'];
        $sub_content      =     $db_field['sub_content'];
}
}
mysql_close($dbc);
MrPizzaFace
  • 7,807
  • 15
  • 79
  • 123

2 Answers2

1

You should remove the semi-colon after your while statement since it won't execute the following enclosure (meaning your query is fine, but the while statement is invalid).

Also, I'm not sure, but the statement:

$id     =     $db_field['ID'];

Might generate an error if the mysql field is 'id' (lowercase). While MySQL isn't (usually) case sensitive, php array keys are, so it may be that the key is only available as 'id' and not 'ID'...

Kasapo
  • 5,294
  • 1
  • 19
  • 21
  • no dice... still only populating db info on first page. DB def has info on other pages...... – MrPizzaFace Jul 11 '12 at 19:54
  • But the query above DOES return data when executed at the SQL command line? If so, check the precise value of "this_page", maybe print it out like ``echo "[$this_page]"`` so you can see any offending whitespace or other issues in case it is being added somehow. – Kasapo Jul 11 '12 at 19:55
  • printing correctly. no white space or other chars. all values in DB for the row are filled (no empty cols) spelling is correct on page name no white space or special chars.. strange that first page works CORRECTLY but subsequent pages have UNDEFINED errors – MrPizzaFace Jul 11 '12 at 19:59
  • is it this line? `` $id = $db_field['ID'];`` -- should that be $db_field['id']? I know MySQL usually isn't case sensitive, but the array key is – Kasapo Jul 11 '12 at 20:01
  • Wow good catch i have no idea how that ID changed case... that really blows my mind... However it is still not working... same error undefined variable.. – MrPizzaFace Jul 11 '12 at 20:06
  • dammit! Does it say which variable is undefined? – Kasapo Jul 11 '12 at 20:06
  • Also -- which version of php are you using? You can usually find this by calling "phpinfo()" within a page. mysql_fetch_assoc isn't available on really really early versions of PHP-4. You might also try "mysql_fetch_row" or "mysql_result" to see if you can access any of the data after the 2nd query. – Kasapo Jul 11 '12 at 20:10
0

Turns out that an empty field from a relational db table (just 1 black field) which is set to not null was causing this undefined break error.. ON ALL PAGES except the home page..

Thank you to all the people who tried to help me.

MrPizzaFace
  • 7,807
  • 15
  • 79
  • 123
  • yeah thanks Kasapo for your help.. check out my new problem -> http://stackoverflow.com/questions/11441631/php-get-all-matching-rows-in-relational-mysql-innodb-database lol – MrPizzaFace Jul 11 '12 at 21:36