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);
10
  • Have you tried running that query straight in the database to see what it returns? Commented Jul 11, 2012 at 19:43
  • 2
    no error due to no error checking! Commented Jul 11, 2012 at 19:46
  • It was working fine. Suddenly now i reverted back to my script before doing the SQL_page_exist and now it doesn't work like it did before. WTH? Commented Jul 11, 2012 at 19:47
  • $result = mysql_query($SQL) or die(mysql_error()); what does it say? Commented Jul 11, 2012 at 19:50
  • 1
    Do you actually output the data you're fetchign in that last section? I see a fetch loop, but no output. Commented Jul 11, 2012 at 20:20

2 Answers 2

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'...

Sign up to request clarification or add additional context in comments.

7 Comments

no dice... still only populating db info on first page. DB def has info on other pages......
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.
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
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
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..
|
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.

1 Comment

yeah thanks Kasapo for your help.. check out my new problem -> stackoverflow.com/questions/11441631/… lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.