Jump to content


Photo

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


  • Please log in to reply
10 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 05 July 2006 - 04:40 AM

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

<?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);
?>
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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 04:47 AM

You have one too many . 's on the end of concatinating all those $_POST elements.

A better idea. Skip all that and...

<?php
$writetocsv = implode(",",$_POST);
$file = fopen("upload.csv","a");
fwrite($fp,$writetocsv);
$fclose ($file);
?>

Oh... sorry. Didn't explain what the dots do. They concatinate (join) strings. So... as an example.

$a = "foo";
$b = "bar";
echo $a . $b;

Would produce the word foobar


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 04:51 AM

You're missing something between this:
$_POST['hit_counter'] $_POST['end_hour']

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:
<?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);
?>

Ken

#4 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 05 July 2006 - 04:53 AM

You mean I spent all that time typing them in, ever so carefully, and there is a way to get around it.....  :o

Please explain what that word concatinating

Ken

#5 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 05 July 2006 - 04:54 AM

OOPS, missed your explaination, thanks a bunch

Ken

#6 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 05 July 2006 - 05:00 AM

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

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 05:27 AM

The dots dont show up in the final output. Look at my example again.

Another one.

$a = "foo" . "," . "bar";
echo $a;

Would produce foo,bar

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.

#8 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 05 July 2006 - 06:39 AM

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

#9 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 07:12 AM

kenrbnsn's example should skip the submit button as stated.

If you want to change the order alphabetically you might use ksort otherwise, you'll need to create the $writetocsv variable manulay as you did in your original post.

#10 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 05 July 2006 - 07:16 AM

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 www.forsale4u.ca/uploadform.html 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

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 07:20 AM

Just append an \n to the end of the line. eg;

$a = "a" . "," . "b" . "," . "c" . "\n";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users