Forum Moderators: coopster

Message Too Old, No Replies

php nest problem

nest

         

craign924

5:47 pm on Sep 19, 2010 (gmt 0)

10+ Year Member



hello,

from oscommerce
i have this code to test for login , if logged in then customer can fill out a form . so i am changing things like this

<?php echo $messageStack->output('contact'); ?>


to


'.php echo $messageStack->output('contact').'



i am stuck on this one getting this
<?php
if ($messageStack->size('contact') > 0) {
?>


when changed to
'.
if ($messageStack->size('contact') > 0) {
.'




error:

Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/comta3/public_html/store/buybacks.php on line 124



here is my login test.

<?php 
if ( !tep_session_is_registered('customer_id') )
{
// code for NON-LOGGED-IN goes here
echo 'to use the buyback form you must be loggedin!';
}
else
{
// code for LOGGED-IN goes here

echo '

';
}

?>





if there is an easier way to handle this any suggestions welcome, becasue there are like 30 of these that need to be changed,



thanks craig

enigma1

6:27 pm on Sep 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need the <?php ?> tags. They signify when the php code is emitted in the page and must be parsed by PHP. So whatever is between the

<?php
// PHP Code
?>

And outside the php tags you have HTML or whatever the document type specifies. Why you want to change the tags btw?

craign924

7:41 am on Sep 20, 2010 (gmt 0)

10+ Year Member



i am changing the php tags because the form would be nested inside php tags and the form will have php tags

enigma1

8:29 am on Sep 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See how other forms in osC are setup for example in the login.php:

<td width="100%" valign="top"><?php echo tep_draw_form('login', tep_href_link(FILENAME_LOGIN, 'action=process', 'SSL')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">

The php tags open and close inside the html.

craign924

10:52 am on Sep 20, 2010 (gmt 0)

10+ Year Member



i understand that, what i am concerned with is how to fit this in with my login test-- to test whether or not customer is logged in or not.

enigma1

11:43 am on Sep 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you check the files, throughout the checkout process osc checks the customer presence. Example:

// if the customer is not logged on, redirect them to the login page
if (!tep_session_is_registered('customer_id')) {
// Not logged in
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}

use the tep_session_is_registered function. It checks is the session key is present.

So basically the redirect makes things easy because it can be placed right after the application_top.php inclusion in the scripts. The rest of code can be executed only if the customer logs in. In other words you don't need an "else" or any other code if the script supposed to be executed for logged in customers.

craign924

3:00 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



this is what i have been looking for,

thank you so much!

craig

willybfriendly

2:51 am on Sep 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/comta3/public_html/store/buybacks.php on line 124


Regarding your original error, look at the php line preceding the if statement to see if you missed the semicolon.