Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Weird PHP Error please read
Old 04-12-2005, 07:52 AM Weird PHP Error please read
Raulică's Avatar
Ultra Talker

Posts: 253
Location: Constanta,Romania
Trades: 0
I am trying to build a php script but i receive a weird error
Code:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in httpdocs/new/cl.php on line 164
I cannot understand what is wrong..i see everything to be ok...

PHP Code:
<?
function login()
{
    print <<<EOF
    "html code"
    EOF;
    exit;
}

function check_login(
$vars)
{
    
$dbuser = "user";
    
$dbpass = "user";
    
$dbhost = "localhost";
    
$dbname = "db";
    
$cid = $vars['id_number'];
    
$cpass = $vars['id_password'];
    mysql_connect(
$dbhost,$dbuser,$dbpass);
    mysql_select_db(
$dbname);
    
$query = "select cid,cpass from customers where cid like '$cid'";
    while(
$row = @mysql_fetch_array(mysql_query($query)))
    {
        if(
$row['cpass'] == $cpass)
        {
            return true;
        } else return false;
    }
}

function customer(
$vars)
{
    
$dbuser = "user";
    
$dbpass = "pass";
    
$dbhost = "localhost";
    
$dbname = "db";
    
$cid = $vars['id_number'];
    
$step = $vars['step'];
    mysql_connect(
$dbhost,$dbuser,$dbpass);
    mysql_select_db(
$dbname);
    
$query = "select cid,cname,cdomain,cmd,cnd from customers where cid like '$cid'";
    
$query1 = "select status from status where cid like '$cid'";
    
$row = mysql_fetch_array(mysql_query($query));
    
$row1 = mysql_fetch_array(mysql_query($query1));
    
$full_name = $row['cname'];
    
$domain = $row['cdomain'];
    
$status = $row1['status'];
    
$cmd = $row['cmd'];
    
$cnd = $row['cnd'];
    print <<<EOF
        "html code"
    EOF;
exit;
}

global 
$REQUEST_METHOD;
global 
$HTTP_POST_VARS;
global 
$HTTP_GET_VARS;
$vars = ($REQUEST_METHOD == 'GET') ? $HTTP_GET_VARS : $HTTP_POST_VARS;
foreach (
$vars as $k=>$v$vars[$k] = trim($v);
if(
$vars['step'] == NULL) <- LINE 164
{
    login();
}
if(
$vars['step'] == "login")
{
    if(check_login(
$vars))
    {
        customer(
$vars);
    }
    else
    {
        echo "Wrong username/password.<br>Please retry!<br>";
        login();
    }
}
?>
I tried to comment all that if statement and it still gives me this error,i am really confused what is going on...

Last edited by Raulică; 04-12-2005 at 08:04 AM..
Raulică is offline
Reply With Quote
View Public Profile Visit Raulică's homepage!
 
 
Register now for full access!
Old 04-12-2005, 08:02 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Should this line
PHP Code:
if($row['cpass'] == $cpass
        { 
            return 
true
        } else return 
false
    } 
be more like this
PHP Code:
if($row['cpass'] == $cpass
        { 
            return 
true
        } else {
            return 
false
       }
    } 
or does the else argument not need to be in brackets?
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-12-2005, 08:04 AM
Raulică's Avatar
Ultra Talker

Posts: 253
Location: Constanta,Romania
Trades: 0
I figured it out .. those "print <<<EOF" statements where giving this error.. i replaced them with echo . Thanks
Raulică is offline
Reply With Quote
View Public Profile Visit Raulică's homepage!
 
Old 04-12-2005, 09:10 AM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
EOF; needs to be the very first thing on the line without any spaces before it.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 04-12-2005, 09:36 AM
Raulică's Avatar
Ultra Talker

Posts: 253
Location: Constanta,Romania
Trades: 0
Thanks for the tip .
Raulică is offline
Reply With Quote
View Public Profile Visit Raulică's homepage!
 
Old 04-12-2005, 06:21 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by leavethisplace
or does the else argument not need to be in brackets?
Just to answer your question very quickly, coding blocks with only a single statement (such as an else with only a return statement in it) need not be encompassed in braces, but it is considered good programming style to do so.

PHP Code:
<?php

//This is valid code
if(  $btest == true )  x=7;
else                   
j=9;

//But this is immediately more recognizable; better style
if( $btest == true )
{
    
7;
}
else
{
    
9;
}
?>
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Reply     « Reply to Weird PHP Error please read
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43998 seconds with 12 queries