I am new to PHP so please explain to me like you would to a child ^_^. I am trying to write a simple php script and keep getting this error:

Parse error: syntax error, unexpected T_STRING in /home/alertsfortraders/www.addictedtotrading.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 14

<?php
$wpusername = $_POST['wpusername'];
$symbol = $_POST['symbol'];
$type = $_POST['type'];
$alert = $_POST['alert'];
$trigger = $_POST['trigger'];
$price = $_POST['price'];


//now we open the file using the a flag, this will create the file if
//it does not exist, and puts the pointer(where it starts writing) at the
//end of the file 
$filename = "pricealerts.csv";
$handle = chmod('/dir/path','0777') fopen($filename, 'b');

//now we prepare our string to be added:
$string_to_add = "$wpusername,$symbol,$type,$alert,$trigger,$price, \n";
fwrite($handle, $string_to_add);

//now close the file
fclose($handle);

?>

the unexpected t_string usually means missing semicolon. ";" but your line is fine. you can try this and see if it works

<?php
$wpusername = $_POST['wpusername'];
$symbol = $_POST['symbol'];
$type = $_POST['type'];
$alert = $_POST['alert'];
$trigger = $_POST['trigger'];
$price = $_POST['price'];


//now we open the file using the a flag, this will create the file if
//it does not exist, and puts the pointer(where it starts writing) at the
//end of the file 
$filename = "pricealerts.csv";
$handle = chmod("/dir/path","0777");
fopen($filename, "b");

//now we prepare our string to be added:
$string_to_add = "$wpusername,$symbol,$type,$alert,$trigger,$price, \n";
fwrite($handle, $string_to_add);

//now close the file
fclose($handle);

?>

That did not work, in fact it caused more errors

hmm well using the original code you posted have you made sure that the file (pricealerts.csv) exist, and is the directory path correct? is the the full code of the page?

The file exists in the root directory. I am not sure if this is wrong or not.

That is all the code i have. What im trying to do is have an Html contact form post directly to a csv file.I found this code on the internet that says it should do somehting like that

Member Avatar for Zagga

Hi alertsfortrader.

Try replacing line 14 (of your original code) with the following

$handle = @fopen($filename,"a+b") or die("Unable to open logfile");

You may need to chmod the file (once) manually (with your ftp client).


Zagga

Now im getting this Parse error: syntax error, unexpected T_VARIABLE on line 17

Member Avatar for Zagga

Hi again alertsfortrader,

Try changing line 17 to . . .

$string_to_add = $wpusername . $symbol . $type . $alert . $trigger . $price . "\n";
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.