Jump to content

Parse error: syntax error, unexpected T_VARIABLE in ERROR, any ideas why


Recommended Posts

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,

Ken

Thanks,

Ken
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]
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
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
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.
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
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.
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.