Page 1 of 1

Little progblem with variables

Posted: Wed Aug 28, 2002 8:57 am
by Zeceer

$fil = brukere/$_POST['brukernavn']$_POST['passord']
$open = fopen( $fil, 'a' );
fputs( $open, "i wrote this" );
This wont work. I always have problem with the new way of posting variables.

This is what the script results:
Parse error: parse error, unexpected T_VARIABLE in D:\inc shop\leggtilihandlekurv.php on line 9
Line 9 is
$fil = brukere/$_POST['brukernavn']$_POST['passord']

Posted: Wed Aug 28, 2002 9:01 am
by volka
PHP is not bash (or another unix shell)
you have to concatenate strings

Code: Select all

$fil = 'brukere/'.$_POSTї'brukernavn'].$_POSTї'passord'];
or have them replaced within a string 'statement'

Code: Select all

$fil = "brukere/{$_POSTї'brukernavn']}{$_POSTї'passord']}";

Posted: Wed Aug 28, 2002 9:07 am
by Zeceer
Thanx

Posted: Wed Aug 28, 2002 9:17 am
by Zeceer

Code: Select all

<?php

if( $_POST&#1111;'brukernavn']=="" or $_POST&#1111;'passord']=="" )
    &#123;
            print("Vennligst fyll ut begge felt!");
    &#125;
else
    &#123;
            if( is_file( 'brukere/'.$_POST&#1111;'brukernavn'].$_POST&#1111;'passord'].'.php' )
                         &#123;
                                  $fil = 'brukere/'.$_POST&#1111;'brukernavn'].$_POST&#1111;'passord'].'.php';
                                  $open = fopen( $fil, 'a' );
                                  fputs( $open, $_POST&#1111;'produkt'] );
                         &#125;
            else
                         &#123;
                                 print("Du er ikke registrert bruker!");
                         &#125;
    &#125;

?>
Have in ****** can I get an error that says

Code: Select all

Parse error: parse error, unexpected '&#123;' in D:\inc shop\leggtilihandlekurv.php on line 10
I get this error sometimes when using if. But why? And hva can I make it go away?

Posted: Wed Aug 28, 2002 10:21 am
by mikeq
if( is_file( 'brukere/'.$_POST['brukernavn'].$_POST['passord'].'.php' ) ) missing parenthesis here.


Get yourself a PHP editor like PHPEdit this will help highlight things like this.

Posted: Thu Aug 29, 2002 2:24 am
by twigletmac

Code: Select all

<?php 

if (empty($_POST&#1111;'brukernavn']) || empty($_POST&#1111;'passord'])) &#123; 
	print 'Vennligst fyll ut begge felt!'; 
&#125; else &#123; 
	if (is_file('brukere/'.$_POST&#1111;'brukernavn'].$_POST&#1111;'passord'].'.php')) &#123; 
		$fil = 'brukere/'.$_POST&#1111;'brukernavn'].$_POST&#1111;'passord'].'.php'; 
		$open = fopen($fil, 'a'); 
		fputs($open, $_POST&#1111;'produkt']); 
	&#125; else &#123; 
        print 'Du er ikke registrert bruker!'; 
	&#125; 
&#125; 

?>