Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

PHP Programming

My OS is win 7 64 bit and I am trying to write a short PHP file, but I am getting an error just after the line : include ('rightbar.php').  The error is :
PHP Parse error: syntax error, unexpected '}' in C:\wamp\www\sattv\icontact.php on line 19
I am using the wamp App for this exercise and the file is saved in the above directory.
If I leave the following line, header('Location: http://www.satellitedirect.com/');
the error is on that line, and if I were to comment out this line, then the error is on the next line of  the code at '}'
The error for the '}' is  
PHP Parse error: syntax error, unexpected '}' in C:\wamp\www\sattv\icontact.php on line 19

I am just getting into PHP and trying to create some practice Apps. Any help will be appreciated.   Please let me know what I am doing wrong.  thank u.  
The code is :
<html>
<head>
</head>
<body>
<?php

$value = $_GET['mail'];

if (empty($value) || $value == "Your Primary Email"){
      header('Location: http://www.satellitedirect.com/');
}else{

//      $handle = fopen('icontactlist.txt', 'a');
//      fwrite($handle, " ".$value);
//      fclose($handle);

include ('rightbar.php')
header('Location: http://www.satellitedirect.com/');
}
?>
</body>
</html>
0
jegajothy
Asked:
jegajothy
  • 2
  • 2
3 Solutions
 
zappafan2k2Commented:
You don't have a semicolon at the end of this line:
include ('rightbar.php')
It should be
include ('rightbar.php');
0
 
jegajothyAuthor Commented:
in response to zappafan, when I corrected it, and compiled and published it, the error is now:
PHP Notice: Undefined index: mail in C:\wamp\www\sattv\icontact.php on line 7 PHP Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\sattv\icontact.php:5) in C:\wamp\www\sattv\icontact.php on line 10
fyi, line 7 = $value = $_GET [ 'mail'];
and line 10 is :  header('Location: http://www.satellitedirect.com/');

My apologies and thank u for noting that missing ;.
0
 
zappafan2k2Commented:
Right.  You're assuming that there is a GET variable named "mail" and if it isn't set, and you have errors on, you'll get that warning.

I usually write lines like that as such:
$value = isset($_GET['mail']) ?  $_GET['mail'] : "Your Primary Email";

if ($value == "Your Primary Email"){

Open in new window

Now you don't have to check if $value is empty, because it's guaranteed to be defined.
0
 
Dave BaldwinFixer of ProblemsCommented:
You get the new error message because you have HTML and text output before you have the 'header' statement.  Since 'header's must be sent before any content, that causes an error.  Even a single space at the beginning of your PHP file can cause that.  http://us.php.net/manual/en/function.header.php  You can use 'output buffering' http://php.net/manual/en/function.ob-start.php to get around that limitation.
0
 
jegajothyAuthor Commented:
Thank u for your sharp eyes.  Goes without saying, your tons of experience can spot a boo boo a mile way.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now