kenwvs Posted July 5, 2006 Share Posted July 5, 2006 I have a basic script (first one I am attempting) and have this error haunting me. I have looked for all kinds of syntax errors, but must be going blind, so any help would be appreciated.Parse error: syntax error, unexpected T_VARIABLE in /home/forsa7/public_html/upload2.php on line 3[code]<?php$writetocsv = $_POST['item_title'] . "," . $_POST['item_category'] . "," . $_POST['item_type'] . "," . $_POST['quantity_available'] . "," . $_POST['starting_bid/price'] . "," . $_POST['bid_increment'] . "," . $_POST['reserve_price'] . "," . $_POST['duration'] . "," . $_POST['auto_relist'] $_POST['city'] . "," . $_POST['state'] . "," . $_POST['country'] $_POST['item_description'] . "," . $_POST['paypal_id'] . "," . $_POST['hit_counter'] $_POST['end_hour'] . "," . ;$file = fopen("upload.csv","a");fwrite($fp,$writetocsv);$fclose ($file);?>[/code]there could very well be more that needs to be added to this script, I am kinda going one step at a time, and trying to make an idea work. I would appreciate it if someone could explain what the cause of this error is. I am not sure what the periods throughout the first line are for, as the examples I have been watching don't show them, but they were in the one example, so thought I would try putting them in.thanks,KenThanks,Ken Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/ Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 You have one too many . 's on the end of concatinating all those $_POST elements.A better idea. Skip all that and...[code=php:0]<?php$writetocsv = implode(",",$_POST);$file = fopen("upload.csv","a");fwrite($fp,$writetocsv);$fclose ($file);?>[/code]Oh... sorry. Didn't explain what the dots do. They concatinate (join) strings. So... as an example.[code=php:0]$a = "foo";$b = "bar";echo $a . $b;[/code]Would produce the word [i]foobar[/i] Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53174 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 You're missing something between this:[code] $_POST['hit_counter'] $_POST['end_hour'] [/code]BTW, the first paramenter in your fwrite() function has to be the variable $file and there's no $ infront of the fclose() function.I'm assuming you're writing everything that's in the $_POST array except the submit button, an easier way to do this would be:[code]<?php$tmp = array();foreach($_POST as $k => $v) if ($k != 'submit') $tmp[] = $v;$fp = fopen('upload.csv','a');fwrite($fp,implode(',',$tmp)."\n");fclose($fp);?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53176 Share on other sites More sharing options...
kenwvs Posted July 5, 2006 Author Share Posted July 5, 2006 You mean I spent all that time typing them in, ever so carefully, and there is a way to get around it..... :oPlease explain what that word concatinatingKen Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53179 Share on other sites More sharing options...
kenwvs Posted July 5, 2006 Author Share Posted July 5, 2006 OOPS, missed your explaination, thanks a bunchKen Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53180 Share on other sites More sharing options...
kenwvs Posted July 5, 2006 Author Share Posted July 5, 2006 just read the replies again, and again, and am getting a headache and confused...... two different answers......... will they both result in the same end result?If those dots join strings would I be correct in assuming I don't want them if I am working on a csv file, hence the ',' to separate them throughout the $Post strings?Ken Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53182 Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 The dots dont show up in the final output. Look at my example again.Another one.[code=php:0]$a = "foo" . "," . "bar";echo $a;[/code]Would produce [i]foo,bar[/i]The other solutions kenrbnsn and myself posted are just better ways to achieve the same result. Mine, however still has your errors in it (that kenrbnsn pointed out), I dodn't even look at it. Mine also doesn't take into account the submit button.kenrbnsn's would be the best solution. Providing that is you want ALL the $_POST vars in a .csv file. Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53187 Share on other sites More sharing options...
kenwvs Posted July 5, 2006 Author Share Posted July 5, 2006 Based on the two examples that were provided to me as alternatives is there a way to have the results listed in the csv file in a different order than they fit on the form. For cosmetic reasons I would like the form in the same order, but due to the csv file, it needs to be in a specific order.The submit button also appears in the csv file, which again, won't work, can that field be eliminated from appearing in the file.thanks,Ken Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53200 Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 kenrbnsn's example should skip the submit button as stated.If you want to change the order alphabetically you might use [url=http://au3.php.net/manual/en/function.ksort.php]ksort[/url] otherwise, you'll need to create the $writetocsv variable manulay as you did in your original post. Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53201 Share on other sites More sharing options...
kenwvs Posted July 5, 2006 Author Share Posted July 5, 2006 I have manually written the script as I originally did, and have it working. Is it possible that when you press submit on the form, it will automatically end that line so you can enter new data in the form and then press submit again. I am thinking there must be an EOL code, and I just haven't found it yet.If you want to see what I am trying to do, you can go to [url=http://www.forsale4u.ca/unloadform.html]www.forsale4u.ca/uploadform.html[/url] and see the form I have generated, although you won't see any results when you hit submit, and the form isn't quite the way I want it yet.ken Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53202 Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 Just append an \n to the end of the line. eg;[code=php:0]$a = "a" . "," . "b" . "," . "c" . "\n";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13702-parse-error-syntax-error-unexpected-t_variable-in-error-any-ideas-why/#findComment-53203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.