Web Analytics Made Easy -
StatCounter Variables in POST - CodingForum


No announcement yet.

Variables in POST

  • Filter
  • Time
  • Show
Clear All
new posts

  • Variables in POST

    For some reason this code is not working.

    I think it has to do with the way the variables are used in the POST lines. I am trying to combine some text with a variable. so that colorid$colorcheck becomes colorid1, colorid2, etc...

    I've tried lots of different ways...probably hitting all around it...

    $color2 = mysql_query('SELECT * FROM color') or die(mysql_error());
    while($color3 = mysql_fetch_array( $color2 )) {
    $colorcheck = $color3['color_id'];
    if( ! empty($_POST['colorid$colorcheck'])) {
    $coloridf = $_POST['colorid$colorcheck'];
    $color_option_cost = $_POST['color_option_cost{$colorcheck}'];
    $youth = $_POST['youth{$colorcheck}'];
    $adult = $_POST['adult{$colorcheck}'];
    $XL2 = $_POST['2x{$colorcheck}'];
    $XL3 = $_POST['3x{$colorcheck}'];
    $XL4 = $_POST['4x{$colorcheck}'];
    $XL5 = $_POST['5x{$colorcheck}'];
    $XL2cost = $_POST['2xcost{$colorcheck}'];
    $XL3cost = $_POST['3xcost{$colorcheck}'];
    $XL4cost = $_POST['4xcost{$colorcheck}'];
    $XL5cost = $_POST['5xcost{$colorche

  • #2
    the problem is quotes, i strongly recomend DO NOT USE VARIABLES IN STRINGS seperate them like in example:

    echo "here is string and here is ".$variable." and here is another string";


    Free php image upload script
    Personal web developing blog


    • #3
      Yes, the problem is the quotes. But only because you're using single quotes and not double quotes.

      PHP searches through strings encapsulated by double quotes for variables, it does not search through strings encapsulated by single quotes.

      If you changed your code to reflect this, then it should function as expected. I do agree with the previous poster - my prefered method of coding is to always break out of prefered strings and insert my variable. It makes it a lot easier on my eyes (especially when using an editor that supports color coding).

      Give the following syntax a try:

      $color_option_cost = $_POST["color_option_cost{$colorcheck}"];

      an alternate method may be

      $color_option_cost = $_POST["color_option_cost$colorcheck"];

      But thats getting into really bad habits...
      Active PHP/MySQL application developer available for immediate work.
      syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready