Hi, complete newbie and having a syntax error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in xxx on line 7

This is line 7:

fputs($fp, "$_POST['Fullname'],$_POST['Jobtitle'],$_POST['email'],$_POST['file'],\n");

Like i say im a complete newbie to this and from what i gather brackets might be missing etcetc. This was cut and pasted from some other code i found on this site but unfortunately dont have the link to hand.
Please advise, its driving me nuts.
Cheers
Jocky

Recommended Answers

All 5 Replies

This will probably fix it:

fputs($fp, "{$_POST['Fullname']},{$_POST['Jobtitle']},{$_POST['email']},{$_POST['file']},\n");
fputs($fp, "{$_POST['Fullname']},{$_POST['Jobtitle']}, {$_POST['email']} ,{$_POST['file']} ,\n");

Use braces {} to encapsulate variables in string

Wow thanks guys for the immediate response yep that sorted it but highlighted other errors namely in these 2 lines:

.'<input name="file" type="hidden" value="'.$file.'">';
.'Fullname ?<input name="Fullname" type="text"><br>';

The complte code is here:

<?php /*download.php*/
If (!$_POST['file']='') {
/* validate $_POST  any amount of form validation this is just an exercise
or die('invalid information'); */
$file = "./logfiles/logfile.csv";// define the text file, named as .csv excell can open it.
$fp = fopen($file, "a+");//open the text file for writing.
fputs($fp, "{$_POST['Fullname']},{$_POST['Jobtitle']},{$_POST['email']},{$_POST['file']},\n");
fclose($fp);
$path=''; //full path outside the root to downloadable files
header("Content-disposition: attachment; filename={$_POST['file']}");
header('Content-type: application/pdf;');
readfile("$path{$_POST['file']}"); }
else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
.'<input name="file" type="hidden" value="'.$file.'">';
.'Fullname ?<input name="Fullname" type="text"><br>';
.'Jobtitle ?<input name="Jobtitle" type="text"><br>';
.'email ?<input name="email" type="text"><br>';
.'<input name="go" type="submit" Value="Download file"></form>'; }
?>

Any advise is greatly appreciated.

Bingo, thanks pritaeas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.