user1667162
user1667162

Reputation:

PHP combining multiple variable

I am new to php and I have a problem with the following code:

$ID = $_POST["first_name"]
$EXT = ".html"
$DOMAIN = "blabla.com/membersarea/"
$URL =  ($DOMAIN . $ID . $EXT)
header("location: http://".$URL);

Here is the error I'm getting:

Parse error: syntax error, unexpected T_VARIABLE 

The error is on line 3:

$EXT = ".html"

So my question is: is the error because of a point in a php variable?

Upvotes: 1

Views: 118

Answers (3)

Gagan Deep
Gagan Deep

Reputation: 489

you have to put semi-colon at the end of each line to tell php its the end of line and you are going to start next one. So, in your code put semi-colon(;) in the first four lines.

Upvotes: 0

Mr. Alien
Mr. Alien

Reputation: 157294

You need to use ; semi-colon delimiter to say php that this is the end of this line...

<?php
   $ID = $_POST["first_name"];
   $EXT = ".html";
   $DOMAIN = "blabla.com/membersarea/";
   $URL =  ($DOMAIN . $ID . $EXT);
   header("location: http://".$URL);
?>

Also use exit; after header()

<?php
   $ID = $_POST["first_name"]; /* Sanitize your data, atleast use mysqli_real_escape_string()*/
   $EXT = ".html";
   $DOMAIN = "blabla.com/membersarea/";
   $URL =  ($DOMAIN.$ID.$EXT); /* Also don't leave any spaces here */
   header("location: http://".$URL);
   exit;
?>

Upvotes: 1

Muthu Kumaran
Muthu Kumaran

Reputation: 17900

You missed semicolon ; in your code. Each statements should ends with semi-colon ;

<?php
  $ID = $_POST["first_name"];
  $EXT = ".html";
  $DOMAIN = "blabla.com/membersarea/";
  $URL =  ($DOMAIN . $ID . $EXT);
  header("location: http://".$URL);
?>

Upvotes: 7

Related Questions