Current location: Hot Scripts Forums » Programming Languages » PHP » Parse error: unexpected $


Parse error: unexpected $

Reply
  #1 (permalink)  
Old 05-24-04, 12:53 AM
altlprsn altlprsn is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Question Parse error: unexpected $

Please help me somone - this page is what is supposed to display the recipe details that the user has chosen:

http://www.thepastaboard.com/recipes...ed_recipe.php3

from results of search displayed here

http://www.thepastaboard.com/recipes...h_results.php3

from searching here

http://www.thepastaboard.com/recipes...arch_main.php3
[I still haven't worked out the correct query code for the main search page!! - if you submit from the drop-down menu, it returns ALL results, no matter what you choose... But I digress...

Anyway - this is the code I have for the selected_recipe.php3:

PHP Code:

<?php

$name 
'name';
$description 'description';
$fc 'fc';
$source 'source';
$submitted_by 'submitted_by'//I just added these for the heck of it
$yield 'yield';                      //to see if it would make any difference
$prep_time 'prep_time';      // - it doesn't...
$ingredients 'ingredients';
$instructions 'instructions';
$nutritional_info 'nutritional_info';
$page = isset($page) ? ($page) : ''

if (isset(
$page)) {
     if (
$page == 'search_results.php3') {

mysql_connect("""name""pass") or die("Could not connect: "mysql_error());

mysql_select_db("recipes") or die("Could not select database"); 

    
$sql "SELECT name, description, yield, fc, prep_time, source, submitted_by, ingredients, instructions, nutritional_info FROM main";
    
    
$result mysql_query($sql);
    
    while(
$current_recipe_found mysql_fetch_array($result)) {
        echo 
'<b>$name</b></TD>
            <TD COLSPAN="2">$fc</TD></TR>
            <TR><TD>$description</TD>
            <TD>$yield</TD>
            <TD>$prep_time</TD></TR>
            <TR><TD></TD>
            <TD WIDTH="25%">$source</TD>
            <TD WIDTH="20%">$submitted_by</TD></TR>
            <TR><TD WIDTH="55%">$ingredients</TD>
            <TD COLSPAN="2"></TD></TR>
            <TR><TD WIDTH="55%">$instructions</TD>
            <TD COLSPAN="2"></TD></TR>
            <TR><TD COLSPAN="3" HEIGHT="5"></TD></TR>
            <TR><TD WIDTH="55%">$nutritional_info</TD>'
;
        }
    }

?>
But the error I get is:
parse error - unexpected $

that is referring to this line number:

<? include ('./footer2.inc'); ?>

-which is just an include file that seems to work fine in other pages (and incidentally, there is another include before this one in the code of selected_recipe.php3...

Does anyone have any ideas???
Reply With Quote
  #2 (permalink)  
Old 05-24-04, 05:11 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
a messing } at the end of file just put a last } and it should go !

and do you really have to write all these field names instead of useing * in your SQL Query?
I mean using this is clearer:
Code:
SELECT * FROM main;
also in the while loop, you are printing the same messages over and over !
use extract() if you don't want to use the array method:
PHP Code:

while($current_recipe_found mysql_fetch_array($result)) { 

   
extract($current_recipe_found);
        echo 
'<b>$name</b></TD> 
            <TD COLSPAN="2">$fc</TD></TR> 
            <TR><TD>$description</TD> 
            <TD>$yield</TD> 
            <TD>$prep_time</TD></TR> 
            <TR><TD></TD> 
            <TD WIDTH="25%">$source</TD> 
            <TD WIDTH="20%">$submitted_by</TD></TR> 
            <TR><TD WIDTH="55%">$ingredients</TD> 
            <TD COLSPAN="2"></TD></TR> 
            <TR><TD WIDTH="55%">$instructions</TD> 
            <TD COLSPAN="2"></TD></TR> 
            <TR><TD COLSPAN="3" HEIGHT="5"></TD></TR> 
            <TR><TD WIDTH="55%">$nutritional_info</TD>'


__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 05-24-04, 10:52 PM
altlprsn altlprsn is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Question Ok. but I'm still having no result ???

Ok, I implemented your suggestion (d'oh!!! )
however, while I am not getting error messages, I am getting no result... I don't understand why? here is the code I have now:

PHP Code:

<?

     
if ($page == 'search_results.php3') {

mysql_connect("""name""pass") or die("Could not connect: "mysql_error());

mysql_select_db("recipes") or die("Could not select database"); 

    
$sql "SELECT * FROM main";
    
$result mysql_query($sql);

$name 'name';
$description 'description';
$fc 'fc';
$source 'source';
$submitted_by 'submitted_by';
$yield 'yield';
$prep_time 'prep_time';
$ingredients 'ingredients';
$instructions 'instructions';
$nutritional_info 'nutritional_info';
    
    while(
$current_recipe_found mysql_fetch_array($result)) { 
           
extract($current_recipe_found); 
                echo 
'<b>$name</b></TD> 
                    <TD COLSPAN="2">$fc</TD></TR> 
                    <TR><TD>$description</TD> 
                    <TD>$yield</TD> 
                    <TD>$prep_time</TD></TR> 
                    <TR><TD></TD> 
                    <TD WIDTH="25%">$source</TD> 
                    <TD WIDTH="20%">$submitted_by</TD></TR> 
                    <TR><TD WIDTH="55%">$ingredients</TD> 
                    <TD COLSPAN="2"></TD></TR> 
                    <TR><TD WIDTH="55%">$instructions</TD> 
                    <TD COLSPAN="2"></TD></TR> 
                   <TR><TD COLSPAN="3" HEIGHT="5"></TD></TR> 
                   <TR><TD WIDTH="55%">$nutritional_info</TD>'
;
        }
    }
}
?>
Is there something glaringly obvious that I am missing??? I can't figure out why it is not printing (echo-ing) the data in the specified fields in the table row for the current recipe found...

Any ideas? All help is appreciated!
Reply With Quote
  #4 (permalink)  
Old 05-25-04, 12:59 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

From what I can see, you are using variable names ($var_name) inside single quotation (after extracting them in the while() loop). This should print the var names as they are and not what's inside them. You should use double-quotation OR escape each var name if you don't want to literally print them.

HTH.

[EDIT]

Also, if you are not getting anything at all, then run your SQL statement directly at MySQL client and see if you are getting anything. If empty set, that means either your SQL is not retrieving what you are trying to or simply there is no data that matches your SQL condition.
__________________
Blavv =|

Last edited by blaw; 05-25-04 at 01:01 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse Error Help, PLEASE!! mrgis PHP 1 05-23-04 05:15 AM
parse error help fraggle PHP 3 04-21-04 03:49 PM
Parse html script [PHP+Mysql] NightRave Script Requests 0 03-23-04 12:02 PM
[php error] parse error | fatal error xeoHosting PHP 1 01-03-04 08:12 PM
PHP script to parse HTML Skeleton Man Script Requests 2 10-05-03 08:41 PM


All times are GMT -5. The time now is 10:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.