php help

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Tue May 01, 2012 12:34 pm

Hi

I am following a tutorial that is like 3 years old lol

All is good apart from this error


Parse error: syntax error, unexpected T_EMPTY in C:\wamp\www\formtest\formtest.php on line 15

This is line 15

if(empty($fn) empty($ln) && empty($address) && empty($city) && empty($state) && empty($zip) && empty($phone) && empty($email)){/*show the form*/

I googled it and tried to over come it with what other people saying it could be but nothing worked

Please help

Thanks in advance

Ian
User avatar
minimihi
php-forum GURU
php-forum GURU
Posts: 236
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania

Tue May 01, 2012 12:47 pm

if(empty($fn) empty($ln) ...
to
if(empty($fn) && empty($ln) ...
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Tue May 01, 2012 12:55 pm

Hi minimihi

thank you for the reply

that fixed that error and now got this one below

Parse error: syntax error, unexpected $end in C:\wamp\www\formtest\formtest.php on line 77

on line 77 is </html>
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Tue May 01, 2012 1:09 pm

from what I have been reading, I am mssing a }

but not too sure where it goes

Code: Select all

<?php
$fn = $_POST['fn'];
$ln = $_POST['ln'];
$address = $_POST['address'];
$city = $_POST['city'];
$fstate = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$emailMe = $_POST['emailMe'];
$comments = $_POST['comments'];

//validate

if(empty($fn) && empty($ln) && empty($address) && empty($city) && empty($state) && empty($zip) && empty($phone) && empty($email)){/*show the form*/
$message = 'Fill in areas in red!'; $aClass = 'errorClass';

/*this is where the creating of the csv takes place*/
$csvData = $fn . "," . $ln . "," . $address. "," . $city. ",". $state. "," . $zip. ",". $phone. ",". $email. ",". $emailMe. "," .$comments."\n";

$fp = fopen("formTest.csv","a");//$fp is now the file pointer to file $filename

if($fp){
fwrite($fp,$csvData);//write information to the file
fclose($fp); //close the file
?>
<body>
<form id="form1" name="form1" method="post" action="<=$_SERVER['PHP_SELF'];?>">
<table class="formatTblClass">
<tr>
<th colspan="6"><?=$message;?></th>
</tr>
<tr>
<td width="68"><span>First Name</span></td>
<td width="215"><input class="<?=$aClass;?>" type="=text" name="fn" id="fn" /></td>
<td width="62"><span>Last Name</span></td>
<td colspan="3"><input class="<?=$aClass;?>" name="In" type="text" id="In" size="50" /></td>
</tr>
<tr>
<td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="71">Address</td>
<td width="721"><input class="<?=$aClass;?>" name="address" type="text" id="address" size="100" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><span>City</span></td>
<td><input class="<?=$aClass;?>" type="text" name="city" id="city" /></td>
<td><span>State</span></td>
<td width="148"><input class="<?=$aClass;?>" type="text" name="state" id="state" /></td>
<td width="24"><span>Zip</span></td>
<td width="255"><input class="<?=$aClass;?>" type="text" name="zip" id="zip" /></td>
</tr>
<tr>
<td><span>Phone</span></td>
<td><input class="<?=$aClass;?>" type="text" name="phone" id="phone" /></td>
<td><span>Email</span></td>
<td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
<td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
<td>Please send me email</td>
</tr>
<tr>
<td colspan="6"><span>Comments
<textarea name="comments" id="comments" cols="45" rows="5"></textarea>
</span>
<div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="Reset" id="button" value="Reset" />
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
User avatar
minimihi
php-forum GURU
php-forum GURU
Posts: 236
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania

Tue May 01, 2012 2:55 pm

I think it should look like this

Code: Select all

if(empty($fn) && empty($ln) && empty($address) && empty($city) && empty($state) && empty($zip) && empty($phone) && empty($email)) { /*show the form*/
    $message = 'Fill in areas in red!'; $aClass = 'errorClass';
} else {
/*this is where the creating of the csv takes place*/
    $csvData = $fn . "," . $ln . "," . $address. "," . $city. ",". $state. "," . $zip. ",". $phone. ",". $email. ",". $emailMe. "," .$comments."\n";

    $fp = fopen("formTest.csv","a");//$fp is now the file pointer to file $filename

    if($fp){
        fwrite($fp,$csvData);//write information to the file
        fclose($fp); //close the file
    }
} 
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Wed May 02, 2012 12:17 am

Hi minimihi

that fixed that error thank you so much but then I got these

Notice: Undefined index: fn in C:\wamp\www\formtest\formtest.php on line 2

Notice: Undefined index: ln in C:\wamp\www\formtest\formtest.php on line 3

Notice: Undefined index: address in C:\wamp\www\formtest\formtest.php on line 4

I did put in the following

error_reporting(E_ALL ^ E_NOTICE);

but found out that just disables the error message, the error is still there

Is the error lines to do with the following lines

Code: Select all

$fn = $_POST['fn'];
$ln = $_POST['ln'];
$address = $_POST['address'];
$city = $_POST['city'];
$fstate = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$emailMe = $_POST['emailMe'];
$comments = $_POST['comments'];
any ideas
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Wed May 02, 2012 12:28 am

Hi minimihi

I fixed all the coding now

just got this small error

when I click on submit, I get the following

Forbidden

You don't have permission to access /formtest/<=$_SERVER['PHP_SELF']; on this server.

im guessing it has something to do with the following line

Code: Select all

<form id="form1" name="form1" method="post" action="<=$_SERVER['PHP_SELF'];?>">
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Wed May 02, 2012 8:46 am

I think I have solved it

I changed the following line

<form id="form1" name="form1" method="post" action="<=$_SERVER['PHP_SELF'];?>">

I changed it to the following

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
ianhaney
php-forum Fan User
php-forum Fan User
Posts: 62
Joined: Tue May 01, 2012 12:30 pm

Wed May 02, 2012 8:53 am

still testing and have now got a small problem

It is storing the data in the csv file but its inputting the names of the headings

I know what part of the code it is to do with but how do I get the coding to store the information that the user puts in

The coding is below

Code: Select all

<?php

$fn = $_POST['fn'] = "First Name";
$ln = $_POST['ln'] = "Last Name";
$address = $_POST['address'] = "Address";
$city = $_POST['city'] = "City";
$fstate = $_POST['state'] = "State";
$zip = $_POST['zip'] = "Zip";
$phone = $_POST['phone'] = "Phone";
$email = $_POST['email'] = "Email";
$emailMe = $_POST['emailMe'] = "Email Me";
$comments = $_POST['comments'] = "Comments";

//validate

if(empty($fn) && empty($ln) && empty($address) && empty($city) && empty($state) && empty($zip) && empty($phone) && empty($email)) { /*show the form*/
    $message = 'Fill in areas in red!'; $aClass = 'errorClass';
} else {
/*this is where the creating of the csv takes place*/
    $csvData = $fn . "," . $ln . "," . $address. "," . $city. ",". $fstate . "," . $zip. ",". $phone. ",". $email . ",". $emailMe . "," .$comments ."\n";

    $fp = fopen("formTest.csv","a");//$fp is now the file pointer to file $filename

    if($fp){
        fwrite($fp,$csvData);//write information to the file
        fclose($fp); //close the file
    }
}
?>
<body>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table class="formatTblClass">
<tr>
<th colspan="6"><?=$message;?></th>
</tr>
<tr>
<td width="68"><span>First Name</span></td>
<td width="215"><input class="<?=$aClass;?>" type="=text" name="fn" id="fn" /></td>
<td width="62"><span>Last Name</span></td>
<td colspan="3"><input class="<?=$aClass;?>" name="In" type="text" id="In" size="50" /></td>
</tr>
<tr>
<td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="71">Address</td>
<td width="721"><input class="<?=$aClass;?>" name="address" type="text" id="address" size="100" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><span>City</span></td>
<td><input class="<?=$aClass;?>" type="text" name="city" id="city" /></td>
<td><span>State</span></td>
<td width="148"><input class="<?=$aClass;?>" type="text" name="state" id="state" /></td>
<td width="24"><span>Zip</span></td>
<td width="255"><input class="<?=$aClass;?>" type="text" name="zip" id="zip" /></td>
</tr>
<tr>
<td><span>Phone</span></td>
<td><input class="<?=$aClass;?>" type="text" name="phone" id="phone" /></td>
<td><span>Email</span></td>
<td><input class="<?=$aClass;?>" type="text" name="email" id="email" /></td>
<td><input name="emailMe" type="checkbox" id="emailMe" value="Yes" checked="checked" /></td>
<td>Please send me email</td>
</tr>
<tr>
<td colspan="6"><span>Comments
<textarea name="comments" id="comments" cols="45" rows="5"></textarea>
</span>
<div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="Reset" id="button" value="Reset" />
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
Post Reply