Jump to content

fbliss

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fbliss's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [code] (HTML) ... <input type=checkbox name="var1[]" value="a" checked> <input type=checkbox name="var1[]" value="b" checked> ... (PHP) <?php print_r($_POST); /* You'd be able to traverse the var1 array like: foreach ($_POST['var1'] as $key => $value) { ... */ ?> (output) Array (     [var1] => Array         (             [0] => a             [1] => b         ) ) [/code] That is VERY cool, just like control arrays in good ole' VB.  That will certainly help cut down on server side code. regarding why the '$var1' parsing not working, I can only guess it has to do with something I did incorrectly.  Being a noob sucks sometimes! The form is doing everything correctly (albeit very inefficiently, I'm sure).  now to move onto some client-side validation... :P Thanks again! F
  2. Hi, the print_r piece helped me sort it out.  I had problems mainly in my sql string - not pulling values in correctly and instead trying to insert the names of the variables.  The iterative code worked fine which was great, but I didn't know about print_r.  I have programming experience so php has been about learning the syntax as well as brushing up on coding efficiency.  I know it's a mess, but I'll worry about that in ver 2.  I just want it working for now. So, my old sql statement when from "('$var1', '$var2', ...)" to the more explicit "('','" . $var1 . "','" . $var2 . "','" . $var3 ... )" I should be able to insert the $var1, $var2 values into a string using {} brackets right?  e.g. "('{$var1}','{$var2}', .... )" If you would like to see what I'm doing I will show you the html/javascript that goes along with it, just PM me. Thanks for your help! fbliss
  3. Hi all I have a form which is built to allow me to enter multiple sets of information using four form controls per set.  Think of it like an invoice in which you put one item on each line, and each item has a name, description, price, etc.  I built a form which allows me to add more sets of these four controls using javascript so I can enter multiple items.  When I have completed adding my items, I then hit the submit button to add what I just key entered to my MySQL Database.  So, if I have two rows of data entered, the code below will add two rows to my MySQL table called 'LINE_ITEMS' and grab the data from each of the four controls per item using $myvar = $_POST['controlx'] where "x" is an appended number referencing the correct control, based on which row the loop is on. Everything here works, the number of rows I've created get added to my table, but no data makes it into the MySQL table.  Note below how I am trying to reference each control in the loops (e.g. itemSel1, txtQuantity1, txtTTValue1, txtSellValue1, then if there is another control set, itemSel2, txtQuantity2, txtTTValue2, txtSellValue2, on and on based on the number of rows (items).) $cArray = array('itemSel','txtQuantity','txtTTValue','txtSellValue'); //the base name of each control before they have their number appended $val_array = array(); //empty array for number of rows $strSQL_C = ''; $cVal = ''; $trans_id = $_GET['trans_id'];//Just a value i pass along from a previous page // // 1 array 4xN $numLines = $_POST['numLines']; //hidden field in my form keeping track of number of rows for the main loop. // 1st loop handles rows, 2nd loop handles columns to refer to each control name for ($i = 0; $i <= $numLines - 1; $i++ ) {   for($j = 0; $j <= 3; $j++ )   {     $iteration = $i + 1; $cVal = $cArray[$j] . (string)$iteration; //Concatenate the name & numerical iteration value to refer to the right control.  this turns each control into it's base name PLUS the row number (e.g. itemSel becomes itemSel1, etc.) *****HERE IS WHERE IT SEEMS TO FAIL FOR SOME REASON********* $val_array[$i][$j] = $_POST['$cVal']; //Get the value for the control, for example,  control itemSel1, or itemSel2 and pull the data in that control.  It seems like $cVal is not being named correctly?  I also tried omitting the single quotes between the $_POST[ ] brackets but no difference. *****END POSSIBLE FAILURE******   } // concatenate the values into one set for the SQL statement. $tempStr = "('$id','$trans_id','$val_array[$i][0]','$val_array[$i][1]','$val_array[$i][2]','$val_array[$i][3]'),";    //Append $tempStr to $strSQL_C. $strSQL_C = $strSQL_C . $tempStr; //**************************next, strip out the final comma from the $strSQL variable.********************************* } $strSQL = rtrim($strSQL_C, ","); // Build a SQL statement with VALUES(fld1, fld2, fld3, fld4), (fld1(2), fld2(2), fld3(2), fld4(2)), etc. // you end up with a 2-dimensional array that holds the values for each control for each row.  4 controls x N rows.   //Change to line_items table $table = "LINE_ITEMS"; $sqlquery = "INSERT INTO $table VALUES" . $strSQL; $results = mysql_query($sqlquery) or die("Sql error: " . mysql_error()); Again, I can get the correct number of rows added to my MySQL table, just no data is actually making it into the database. Help & TIA! F
×
×
  • 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.