0

buy.php:

<form action="cart.php" method="post">
<?php foreach($product['varieties'] as $variety): ?>
    <input style="width:10px; margin-left:9px; " name="price[]" type="checkbox" value="<?php echo $variety['price'] . '_' . $variety['size']; ?>"  />';
<?php end foreach; ?>
</form>

cart.php:

list($aDoor, size)  = split('_', $_POST['price']); // line 207

if(empty($aDoor)) 
{
  echo("You didn't select any buildings.");
} 
else 
{
  echo "Sum of vlues = ".array_sum($aDoor);
}

In cart.php there is the following syntax error:

syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in store/cart.php on line 207

I am expecting in cart.php to receive the two index values size and price independetly so I can use it and CSS it where ever i want. I am expecting that with the function list() and split() the variables variety and $aDoor with the price value will able to separate this two variables to be use wherever I want in cart.php

Help.

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
jona
  • 101
  • 1
  • 1
  • 7

5 Answers5

4

Missing a $:

list($aDoor, $size) = split('_', $_POST['price']); // line 207

I think you are trying to do something like:

<?php
$aDoor = array();
$size = array();

foreach ($_POST['price'] as $p)
{
  list($a, $b) = explode('_', $p);
  $aDoor[] = $a;
  $size[] = $b;
}

if(empty($aDoor)) 
{
  echo("You didn't select any buildings.");
} 
else 
{
  echo "Sum of vlues = ".array_sum($aDoor);
}

?>
Matthew
  • 47,584
  • 11
  • 86
  • 98
  • Yepp is missing the dolar sign – streetparade Feb 11 '10 at 23:48
  • This seem to be ok to use list($aDoor, $size) = split('_', $_POST['price']); But how can I $size is a string and $aDoor are numbers to sum the numbers I can easly do by echo "Sum of vlues = ".array_sum($aDoor); But how can I list the string inside of $size? foreach($size as $variety) { echo '
    '.$variety['size']. '
    } I have tried the above code to receive and echo the content of this varieble but it has print or display anything can any body help me on this? Thank you, Don't know that much of php
    – jona Feb 12 '10 at 00:25
  • I've added an example as best as I can interpret your problem. – Matthew Feb 12 '10 at 00:49
  • check my own answer below for a comment – jona Feb 12 '10 at 18:12
2

See this for a good primer. And Google is your friend :)

Community
  • 1
  • 1
kprobst
  • 16,165
  • 5
  • 32
  • 53
0

It's Hebrew. It means twice colon. It also happens when you miss the $, like you have.

http://en.wikipedia.org/wiki/Scope_resolution_operator#PHP

alex
  • 479,566
  • 201
  • 878
  • 984
0

@Konforce I test your script and it works good.

Sorry I don't know what I was saying but I have to work it like this to list $size and prices $aDoor with the total below. I just have to style it now.

<?php
list($aDoor, $size) = split('_', $_POST['price']);
$aDoor = array();
$size = array();

foreach ($_POST['price'] as $p)
{
  list($a, $b) = explode('_', $p);
  $aDoor[] = $a;
  $size[] = $b;
}

   if(empty($aDoor)) 
{
  echo("You didn't select any buildings.");
} 
else 
{
   $V = count($size);

for($i=0; $i < $V; $i++)
    {

      echo($size[$i] . " ");
    } 
     $A = count($aDoor);
 for($i=0; $i < $A; $i++)
    {

      echo($aDoor[$i] . " ");
    }


  echo "Sum of vlues = ".array_sum($aDoor);
}
?>
jona
  • 101
  • 1
  • 1
  • 7
0

@konforce can you see at the begining where you have set up the variable $aDoor and $size as arrays?

$aDoor = array();
$size = array();

Well now I am adding another index value that is not an array it is an string

<input style="width:10px; margin-left:9px; " name="price[]" type="checkbox" value="' . $variety['price']. '_'. $variety['variety'] '_'. $product['name'].'"  />

you see the '. $product['name'].' well how can I receive it in cart.php in cart.php you have done the script as below but those are for arrays this time this one is not an array and I am seding it through the same form input.

$aDoor = array();
$size = array();

foreach ($_POST['price'] as $p)
{
  list($a, $b) = explode('_', $p);
  $aDoor[] = $a;
  $size[] = $b;
}
jona
  • 101
  • 1
  • 1
  • 7