I continue to get the following error when running the my php script.

PHP Parse error:  syntax error, unexpected T_STRING, expecting ']' in /hermes/bosweb/web171/b1716/sl.c2cadmin/C2C/php/processform.php on line 174

Any insight on this would be greatly appreciated.
Here is the script:

<?php
/*  Program name: processform.php
 *  Description:  Program checks all the form fields for
 *                blank fields and incorrect format. Saves the
 *                correct fields in a database.
 */
?>
<html>
<head><title>Process Form Data</title></head>
<body>
<?php
  /* set up array of field labels */
  $labels = array( "Custnombre" => "Custnombre",
                   "Custemail" => "Custemail",
                   "8x10" => "8x10",
           "8X10quantity" => "8x10quantity",
                   "8x12" => "8x12",
                   "8x12quantity" => "8x12quantity",
           "10x12" => "10x12",
                   "10x12quantity" => "10x12quantity",
           "12x12" => "12x12",
                   "12x12quantity" => "12x12quantity",
           "12x16" => "12x16",
                   "12x16quantity" => "12x16quantity",
           "16x16" => "16x16",
                   "16x16quantity" => "16x16quantity",
           "16x20" => "16x20",
                   "16x20quantity" => "16x20quantity",
           "18x18" => "18x18",
                   "18x18quantity" => "18x18quantity",
           "18x24" => "18x24",
                   "18x24quantity" => "18x24quantity",
           "20x24" => "20x24",
                   "20x24quantity" => "20x24quantity",
           "24x36" => "24x36",
                   "24x36quantity" => "24x36quantity",
           "24x48" => "24x48",
                   "24x48quantity" => "24x48quantity",
           "36x48" => "36x48",
                   "36x48quantity" => "36x48quantity",
           "18x24" => "18x24",
                   "18x24quantity" => "18x24quantity",
           "h8x10" => "h8x10",
                   "h8x12" => "h8x12",
           "h10x12" => "h10x12",
           "h12x12" => "h12x12",
           "h12x16" => "h12x16",
                   "h16x16" => "h16x16",
                   "h16x20" => "h16x20",
                   "h18x18" => "h18x18",
                   "h18x24" => "h18x24",
                   "h20x24" => "h20x24",
                   "h24x36" => "h24x36",
                   "h24x48" => "h24x48",
                   "h36x48" => "h36x48",
                   "h18x24" => "h18x24",
           "photorealistic" => "photorealistic",
           "painted" => "painted",
           "addsvc1" => "addsvc1",
           "addsvc2" => "addsvc2",
           "addsvc3" => "addsvc3",
           "addsvc4" => "addsvc4",
           "imagedetails" => "imagedetails",
           "imagefile" => "imagefile",
           "fileownership" => "fileownership",
           "shipping" => "shipping",
           "address" => "address");
/* Check information from form */
  foreach($_POST as $field => $value)
  {
    /* check each field for blank fields */
    if( $value == "" )
    {
      $blank_array[] = $field;
    }
    /* check format of each field */
    elseif( ereg("(name)",$field) )  
    {
      if(!ereg("^[A-Za-z' -]{1,50}$",$value) )
      {
          $bad_format[] = $field;
      }
    }
    elseif($field == "phone")
    {
      if(!ereg("^[0-9)( -]{7,20}(([xX]|(ext)|(ex))?[ -]?[0-9]{1,7})?$",$value) )
      {
          $bad_format[] = $field;
      }
    }
  } // end of foreach for $_POST
  /* if any fields were not okay, display error message and form */
  if(@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
  {
    if(@sizeof($blank_array) > 0)
    {
        /* display message for missing information */
        echo "<b>You didn't fill in one or more required fields. 
                 You must enter:</b><br>";
        /* display list of missing information */
        foreach($blank_array as $value)
        {
           echo "&nbsp;&nbsp;&nbsp;{$labels[$value]}<br>";
        }
    }
    if(@sizeof($bad_format) > 0)
    {
        /* display message for bad information */
        echo "<b>One or more fields have information that appears to 
                 be incorrect. Correct the format for:</b><br>";
        /* display list of bad information */
        foreach($bad_format as $value)
        {
           echo "&nbsp;&nbsp;&nbsp;{$labels[$value]}<br>";
        }
    }
    /* redisplay form */
    /*echo "<p><hr />";
     *echo "<h3>Please enter your phone number below.</h3>";
     *echo "<form action='processform.php' method='POST'>
    */     

    echo "<table>";

    foreach($labels as $field => $label)
    {
      $good_data[$field]=strip_tags(trim($_POST[$field]));
      echo "<tr>
             <td style='text-align: right; font-weight: bold'>
                $label</td>
             <td><input type='text' name='$field' size='65'
                 maxlength='65' value='$good_data[$field]'></td>
            </tr>";
    }
    echo "<tr>
           <td colspan='2' style='text-align: center'>
              <input type='submit' value='Submit Phone Number'>";
    echo "</td></tr></table>
          </form>";
    exit();
  }
  else   //if data is okay
  {
    $user="";
    $host="";
    $password="";
    $database = "";
    $cxn = mysql_connect($host,$user,$password)
           or die ("couldn't connect to server");
    mysql_select_db($database);

    $fields_all = array_keys($labels);
    foreach($fields_all as $field)
    {
      $good_data[$field] = strip_tags(trim($_POST[$field]));
      if($field == "phone")
      {
         $good_data[$field] = ereg_replace("[)( .-]","",$good_data[$field]);
      }
      $good_data[$field] = mysql_real_escape_string($good_data[$field]);
    }

    $query = "INSERT INTO Customer(Custnombre,Custemail,8x10,8x10quantity,
                   8x12,8x12quantity,10x12,10x12quantity,
                   12x12,12x12quantity,12x16,12x16quantity,
                   16x16,16x16quantity,16x20,16x20quantity,
                   18x18,18x18quantity,18x24,18x24quantity,
                   20x24,20x24quantity,24x36,24x36quantity,
                   24x48,24x48quantity,36x48,36x48quantity,
                   photorealistic,painted,addsvc1,addsvc2,
                   addsvc3,addsvc4,imagedetails,imagefile,
                   fileownership,shipping,address) 
              VALUES ('$good_data[Custnombre]','$good_data[Custemail]','$good_data[8x10]','$good_data[8x10quantity]','$good_data[8x12]','$good_data[8x12quantity]','$good_data[10x12]','$good_data[10x12quantity]','$good_data[12x12]','$good_data[12x12quantity]','$good_data[12x16]','$good_data[12x16quantity]','$good_data[18x18]','$good_data[18x18quantity]','$good_data[18x24]','$good_data[18x24quantity]','$good_data[20x24]','$good_data[20x24quantity]','$good_data[24x36]','$good_data[24x36quantity]','$good_data[24x48]','$good_data[24x48quantity]','$good_data[36x48]','$good_data[36x48quantity]','$good_data[photorealistic]','$good_data[painted]','$good_data[addsvc1]','$good_data[addsvc2]','$good_data[addsvc3]','$good_data[addsvc4]','$good_data[imagedetails]','$good_data[imagefile]','$good_data[fileownership]','$good_data[shipping]','$good_data[address]')";
    $result = mysql_query($query)
              or die ("Couldn't execute query.");
    echo "<div align="center">
  <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Your 
    order has been received!</strong></font></p>
  <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"> <a href="http://www.captured2canvas.com/default.html">Click 
    Here</a> to place another order. </font></p>
  <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Close this window 
    to log out. </font></p>
</div>";
  }
?>
</body></html>

Edited 3 Years Ago by Dani: Formatting fixed

Assign all these values '$good_data[Custnombre]','$good_data[Custemail]','$good_data[8x10]','.... to a variable and try again! And, shouldn't it be $good_data instead of $good_data[8x10] ?

Btw, next time you post your code, please post it within [/code ] tags.[code =php] [/code ] tags.

I continue to get the following error when running the my php script.

PHP Parse error: syntax error, unexpected T_STRING, expecting ']' in /hermes/bosweb/web171/b1716/sl.c2cadmin/C2C/php/processform.php on line 174

Any insight on this would be greatly appreciated.
Here is the script:

<?php /* Program name: processform.php * Description: Program checks all the form fields for * blank fields and incorrect format. Saves the * correct fields in a database. */ ?> <html> <head><title>Process Form Data</title></head> <body> <?php /* set up array of field labels */ $labels = array( "Custnombre" => "Custnombre", "Custemail" => "Custemail", "8x10" => "8x10", "8X10quantity" => "8x10quantity", "8x12" => "8x12", "8x12quantity" => "8x12quantity", "10x12" => "10x12", "10x12quantity" => "10x12quantity", "12x12" => "12x12", "12x12quantity" => "12x12quantity", "12x16" => "12x16", "12x16quantity" => "12x16quantity", "16x16" => "16x16", "16x16quantity" => "16x16quantity", "16x20" => "16x20", "16x20quantity" => "16x20quantity", "18x18" => "18x18", "18x18quantity" => "18x18quantity", "18x24" => "18x24", "18x24quantity" => "18x24quantity", "20x24" => "20x24", "20x24quantity" => "20x24quantity", "24x36" => "24x36", "24x36quantity" => "24x36quantity", "24x48" => "24x48", "24x48quantity" => "24x48quantity", "36x48" => "36x48", "36x48quantity" => "36x48quantity", "18x24" => "18x24", "18x24quantity" => "18x24quantity", "h8x10" => "h8x10", "h8x12" => "h8x12", "h10x12" => "h10x12", "h12x12" => "h12x12", "h12x16" => "h12x16", "h16x16" => "h16x16", "h16x20" => "h16x20", "h18x18" => "h18x18", "h18x24" => "h18x24", "h20x24" => "h20x24", "h24x36" => "h24x36", "h24x48" => "h24x48", "h36x48" => "h36x48", "h18x24" => "h18x24", "photorealistic" => "photorealistic", "painted" => "painted", "addsvc1" => "addsvc1", "addsvc2" => "addsvc2", "addsvc3" => "addsvc3", "addsvc4" => "addsvc4", "imagedetails" => "imagedetails", "imagefile" => "imagefile", "fileownership" => "fileownership", "shipping" => "shipping", "address" => "address"); /* Check information from form */ foreach($_POST as $field => $value) { /* check each field for blank fields */ if( $value == "" ) { $blank_array[] = $field; } /* check format of each field */ elseif( ereg("(name)",$field) ) { if(!ereg("^[A-Za-z' -]{1,50}$",$value) ) { $bad_format[] = $field; } } elseif($field == "phone") { if(!ereg("^[0-9)( -]{7,20}(([xX]|(ext)|(ex))?[ -]?[0-9]{1,7})?$",$value) ) { $bad_format[] = $field; } } } // end of foreach for $_POST /* if any fields were not okay, display error message and form */ if(@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0) { if(@sizeof($blank_array) > 0) { /* display message for missing information */ echo "<b>You didn't fill in one or more required fields. You must enter:</b><br>"; /* display list of missing information */ foreach($blank_array as $value) { echo "&nbsp;&nbsp;&nbsp;{$labels[$value]}<br>"; } } if(@sizeof($bad_format) > 0) { /* display message for bad information */ echo "<b>One or more fields have information that appears to be incorrect. Correct the format for:</b><br>"; /* display list of bad information */ foreach($bad_format as $value) { echo "&nbsp;&nbsp;&nbsp;{$labels[$value]}<br>"; } } /* redisplay form */ /*echo "<p><hr />"; *echo "<h3>Please enter your phone number below.</h3>"; *echo "<form action='processform.php' method='POST'> */

echo "<table>";

foreach($labels as $field => $label) { $good_data[$field]=strip_tags(trim($_POST[$field])); echo "<tr> <td style='text-align: right; font-weight: bold'> $label</td> <td><input type='text' name='$field' size='65' maxlength='65' value='$good_data[$field]'></td> </tr>"; } echo "<tr> <td colspan='2' style='text-align: center'> <input type='submit' value='Submit Phone Number'>"; echo "</td></tr></table> </form>"; exit(); } else //if data is okay { $user=""; $host=""; $password=""; $database = ""; $cxn = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); mysql_select_db($database);

$fields_all = array_keys($labels); foreach($fields_all as $field) { $good_data[$field] = strip_tags(trim($_POST[$field])); if($field == "phone") { $good_data[$field] = ereg_replace("[)( .-]","",$good_data[$field]); } $good_data[$field] = mysql_real_escape_string($good_data[$field]); }

$query = "INSERT INTO Customer(Custnombre,Custemail,8x10,8x10quantity, 8x12,8x12quantity,10x12,10x12quantity, 12x12,12x12quantity,12x16,12x16quantity, 16x16,16x16quantity,16x20,16x20quantity, 18x18,18x18quantity,18x24,18x24quantity, 20x24,20x24quantity,24x36,24x36quantity, 24x48,24x48quantity,36x48,36x48quantity, photorealistic,painted,addsvc1,addsvc2, addsvc3,addsvc4,imagedetails,imagefile, fileownership,shipping,address) VALUES ('$good_data[Custnombre]','$good_data[Custemail]','$good_data[8x10]','$good_data[8x10quantity]','$good_data[8x12]','$good_data[8x12quantity]','$good_data[10x12]','$good_data[10x12quantity]','$good_data[12x12]','$good_data[12x12quantity]','$good_data[12x16]','$good_data[12x16quantity]','$good_data[18x18]','$good_data[18x18quantity]','$good_data[18x24]','$good_data[18x24quantity]','$good_data[20x24]','$good_data[20x24quantity]','$good_data[24x36]','$good_data[24x36quantity]','$good_data[24x48]','$good_data[24x48quantity]','$good_data[36x48]','$good_data[36x48quantity]','$good_data[photorealistic]','$good_data[painted]','$good_data[addsvc1]','$good_data[addsvc2]','$good_data[addsvc3]','$good_data[addsvc4]','$good_data[imagedetails]','$good_data[imagefile]','$good_data[fileownership]','$good_data[shipping]','$good_data[address]')"; $result = mysql_query($query) or die ("Couldn't execute query."); echo "<div align="center"> <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Your order has been received!</strong></font></p> <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"> <a href="http://www.captured2canvas.com/default.html">Click Here</a> to place another order. </font></p> <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Close this window to log out. </font></p> </div>"; } ?> </body></html> [/code ][code =php]<?php
/* Program name: processform.php
* Description: Program checks all the form fields for
* blank fields and incorrect format. Saves the
* correct fields in a database.
*/
?>
<html>
<head><title>Process Form Data</title></head>
<body>
<?php
/* set up array of field labels */
$labels = array( "Custnombre" => "Custnombre",
"Custemail" => "Custemail",
"8x10" => "8x10",
"8X10quantity" => "8x10quantity",
"8x12" => "8x12",
"8x12quantity" => "8x12quantity",
"10x12" => "10x12",
"10x12quantity" => "10x12quantity",
"12x12" => "12x12",
"12x12quantity" => "12x12quantity",
"12x16" => "12x16",
"12x16quantity" => "12x16quantity",
"16x16" => "16x16",
"16x16quantity" => "16x16quantity",
"16x20" => "16x20",
"16x20quantity" => "16x20quantity",
"18x18" => "18x18",
"18x18quantity" => "18x18quantity",
"18x24" => "18x24",
"18x24quantity" => "18x24quantity",
"20x24" => "20x24",
"20x24quantity" => "20x24quantity",
"24x36" => "24x36",
"24x36quantity" => "24x36quantity",
"24x48" => "24x48",
"24x48quantity" => "24x48quantity",
"36x48" => "36x48",
"36x48quantity" => "36x48quantity",
"18x24" => "18x24",
"18x24quantity" => "18x24quantity",
"h8x10" => "h8x10",
"h8x12" => "h8x12",
"h10x12" => "h10x12",
"h12x12" => "h12x12",
"h12x16" => "h12x16",
"h16x16" => "h16x16",
"h16x20" => "h16x20",
"h18x18" => "h18x18",
"h18x24" => "h18x24",
"h20x24" => "h20x24",
"h24x36" => "h24x36",
"h24x48" => "h24x48",
"h36x48" => "h36x48",
"h18x24" => "h18x24",
"photorealistic" => "photorealistic",
"painted" => "painted",
"addsvc1" => "addsvc1",
"addsvc2" => "addsvc2",
"addsvc3" => "addsvc3",
"addsvc4" => "addsvc4",
"imagedetails" => "imagedetails",
"imagefile" => "imagefile",
"fileownership" => "fileownership",
"shipping" => "shipping",
"address" => "address");
/* Check information from form */
foreach($_POST as $field => $value)
{
/* check each field for blank fields */
if( $value == "" )
{
$blank_array[] = $field;
}
/* check format of each field */
elseif( ereg("(name)",$field) )
{
if(!ereg("^[A-Za-z' -]{1,50}$",$value) )
{
$bad_format[] = $field;
}
}
elseif($field == "phone")
{
if(!ereg("^[0-9)( -]{7,20}(([xX]|(ext)|(ex))?[ -]?[0-9]{1,7})?$",$value) )
{
$bad_format[] = $field;
}
}
} // end of foreach for $_POST
/* if any fields were not okay, display error message and form */
if(@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
{
if(@sizeof($blank_array) > 0)
{
/* display message for missing information */
echo "<b>You didn't fill in one or more required fields.
You must enter:</b><br>";
/* display list of missing information */
foreach($blank_array as $value)
{
echo "&nbsp;&nbsp;&nbsp;{$labels[$value]}<br>";
}
}
if(@sizeof($bad_format) > 0)
{
/* display message for bad information */
echo "<b>One or more fields have information that appears to
be incorrect. Correct the format for:</b><br>";
/* display list of bad information */
foreach($bad_format as $value)
{
echo "&nbsp;&nbsp;&nbsp;{$labels[$value]}<br>";
}
}
/* redisplay form */
/*echo "<p><hr />";
*echo "<h3>Please enter your phone number below.</h3>";
*echo "<form action='processform.php' method='POST'>
*/

echo "<table>";

foreach($labels as $field => $label)
{
$good_data[$field]=strip_tags(trim($_POST[$field]));
echo "<tr>
<td style='text-align: right; font-weight: bold'>
$label</td>
<td><input type='text' name='$field' size='65'
maxlength='65' value='$good_data[$field]'></td>
</tr>";
}
echo "<tr>
<td colspan='2' style='text-align: center'>
<input type='submit' value='Submit Phone Number'>";
echo "</td></tr></table>
</form>";
exit();
}
else //if data is okay
{
$user="";
$host="";
$password="";
$database = "";
$cxn = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
mysql_select_db($database);

$fields_all = array_keys($labels);
foreach($fields_all as $field)
{
$good_data[$field] = strip_tags(trim($_POST[$field]));
if($field == "phone")
{
$good_data[$field] = ereg_replace("[)( .-]","",$good_data[$field]);
}
$good_data[$field] = mysql_real_escape_string($good_data[$field]);
}

$query = "INSERT INTO Customer(Custnombre,Custemail,8x10,8x10quantity,
8x12,8x12quantity,10x12,10x12quantity,
12x12,12x12quantity,12x16,12x16quantity,
16x16,16x16quantity,16x20,16x20quantity,
18x18,18x18quantity,18x24,18x24quantity,
20x24,20x24quantity,24x36,24x36quantity,
24x48,24x48quantity,36x48,36x48quantity,
photorealistic,painted,addsvc1,addsvc2,
addsvc3,addsvc4,imagedetails,imagefile,
fileownership,shipping,address)
VALUES ('$good_data[Custnombre]','$good_data[Custemail]','$good_data[8x10]','$good_data[8x10quantity]','$good_data[8x12]','$good_data[8x12quantity]','$good_data[10x12]','$good_data[10x12quantity]','$good_data[12x12]','$good_data[12x12quantity]','$good_data[12x16]','$good_data[12x16quantity]','$good_data[18x18]','$good_data[18x18quantity]','$good_data[18x24]','$good_data[18x24quantity]','$good_data[20x24]','$good_data[20x24quantity]','$good_data[24x36]','$good_data[24x36quantity]','$good_data[24x48]','$good_data[24x48quantity]','$good_data[36x48]','$good_data[36x48quantity]','$good_data[photorealistic]','$good_data[painted]','$good_data[addsvc1]','$good_data[addsvc2]','$good_data[addsvc3]','$good_data[addsvc4]','$good_data[imagedetails]','$good_data[imagefile]','$good_data[fileownership]','$good_data[shipping]','$good_data[address]')";
$result = mysql_query($query)
or die ("Couldn't execute query.");
echo "<div align="center">
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Your
order has been received!</strong></font></p>
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"> <a href="http://www.captured2canvas.com/default.html">Click
Here</a> to place another order. </font></p>
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Close this window
to log out. </font></p>
</div>";
}
?>
</body></html>
[/code ]

(code=php ) (/code ) without the extra whitespace :-/ .
Anyway, Instead of

VALUES ('$good_data[Custnombre]','$good_data[Custemail]','$good_data[8x10]','$good_data[8x10quantity]', '$good_data[8x12]','$good_data[8x12quantity]','$good_data[10x12]','$good_data[10x12quantity]', '$good_data[12x12]','$good_data[12x12quantity]','$good_data[12x16]','$good_data[12x16quantity]', '$good_data[18x18]','$good_data[18x18quantity]','$good_data[18x24]','$good_data[18x24quantity]', '$good_data[20x24]','$good_data[20x24quantity]','$good_data[24x36]','$good_data[24x36quantity]', '$good_data[24x48]','$good_data[24x48quantity]','$good_data[36x48]','$good_data[36x48quantity]', '$good_data[photorealistic]','$good_data[painted]','$good_data[addsvc1]','$good_data[addsvc2]', '$good_data[addsvc3]','$good_data[addsvc4]','$good_data[imagedetails]', '$good_data[imagefile]','$good_data[fileownership]', '$good_data[shipping]','$good_data[address]')";

Use

$val1, $val2, $val3,... where $val1,$val2,$val3 is $good_data['8x10'],$good_data['Custemail'], etc..

Edited 3 Years Ago by mike_2000_17: Fixed formatting

normally if you are going to use array elements inside of an SQL query string you need to put curly braces around them.

VALUES ('{$good_data['Custnombre']}')

Although using array elements isn't really the best way like nav33n said above you really should assign them to regular variables.

also you need to use some sort of quotation mark inside the array elements calls for example
$good_data[[B]'[/B]custnombre[B]'[/B]] otherwise you get errors.

This article has been dead for over six months. Start a new discussion instead.