Little progblem with variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Little progblem with variables

Post 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']
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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']}";
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Thanx
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post 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?
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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; 

?>
Post Reply