| parse error: syntax error, unexpected T VARIABLE
|
alertsfortraders

msg:4183258 | 6:29 pm on Aug 6, 2010 (gmt 0) | I do not even consider myself a newbie with php, I consider myself to know nothing. I am trying to write a simple piece of code but keep getting an error. here is the error i get: Parse error: syntax error, unexpected T_VARIABLE in /home/website/www.example.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()�d code on line 17 Here is my code: <?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); ?> |
| [edited by: dreamcatcher at 5:51 am (utc) on Aug 7, 2010] [edit reason] exemplified server path [/edit]
|
sonjay

msg:4183365 | 10:15 pm on Aug 6, 2010 (gmt 0) | In this line: $filename = "pricealerts.csv\"; The backslash is escaping the quotation mark, so php doesn't think that quoted string is closed until it reaches the first quotation mark in this line: $string_to_add = "$wpusername,$symbol,$type,$alert,$trigger,$price,\n"; At which point, it sees $wpusername as an unexplained variable.
|
alertsfortraders

msg:4183486 | 6:53 am on Aug 7, 2010 (gmt 0) | I removed the \ that you advised me to and got another error. Parse error: syntax error, unexpected T_STRING on line 14 Here is what it is now <?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); ?> |
|
|
Matthew1980

msg:4183495 | 8:24 am on Aug 7, 2010 (gmt 0) | Hi there alertsfortraders, What are you trying to achieve? $handle = chmod('/dir/path','0777') fopen($filename, 'b'); |
| your assigning too much to the 'handle' variable, fopen needs to be on its own line, and preferably setting it's read write directive to 'r+' (read and write) [uk3.php.net ] And chmod() only needs to be set to 755, I have no idea why people try to give absolute full permissions to directories at all, 755 is plenty - at least that's what I usually do, but that's just my opinion :) What is the format of the data in the CSV file (I know as it means comma separated, but you never know) and:- $string_to_add = $wpusername." ".$symbol." ".$type." ".$alert." ".$trigger." ".$price."\n"; |
| I'm guessing as you will want spaces between the individual strings? Then again I am guessing.. If this is all in the same directory you will be fine, but I strongly suggest that you learn to define root folders so that you can make access a little more reliable... Hope I haven't confused you too much. Cheers, MRb
|
|
|