★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/001592.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  PHP
  fields not lining up

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   fields not lining up
bkatsma
Junior Member
posted June 22, 2000 08:07 AM     Click Here to See the Profile for bkatsma   Click Here to Email bkatsma     Edit/Delete Message Reply w/Quote
I have a question that is dificult to explain but I will give it my best.

I have 8 sets of 3 arrays which are enter from an HTML form in the form of a check box, text field and text area.
If a check box is marked I need the information from the text area and test field to be entered as the same field
in the MySQL DB. I did this by having the php code loop through the amout of time as I have check marks. All works
great if I have all check boxes but it all screws up if I have anythin but the first check box checked. I know
this a pretty cryptic discription but have a look at the code and see if any one can help.

NOTE: If I do a count on the arrays the text field and text area they are always 8 and the check box count depends
on how many I have checked. So I believe what is happening enven though I am not putting data int the text field
and text are it is entering this info as blank fields into my DB throwing every thing out of wack.

Thanks

HTML CODE

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="1"> A-Surface
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="2"> B-Surface
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="3"> Drawing
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="4"> Attachments
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="8"> Feasibility
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="5"> P.I.S.T.
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="6"> Data Translation
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="7"> Engineering Change
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td>

PHP CODE to enter data into DB

$numrows = count ($WORK_TYPE_ARRAY);
for ($i = 0; $i < $numrows; ++$i) {

$sql2 = "INSERT INTO tow_details (wo_id, tow_id, tow_datereq, tow_inst) VALUES
('$worknum', '$WORK_TYPE_ARRAY[$i]', '$TOW_DATEREQ_ARRAY[$i]', '$TOW_INST_ARRAY[$i]')";

$result2 = mysql_query($sql2) or die ("Query Failed");

}

THANKS!!!

releasedj
Member
posted June 22, 2000 09:40 AM     Click Here to See the Profile for releasedj     Edit/Delete Message Reply w/Quote
I don't have much time to explain this so I lined up the HTML so it was numbered 1-8 in order, so that you can reference the arrays using this. I then used the var $j - 1 for this figure.
It goes through each array value in $WORK_TYPE_ARRAY, gets the value, and uses it to reference the other arrays.

Well here's the code, you might want to replace the replace the;
$result2 = mysql_query($sql2) or die ("Query Failed");
with
print("$sql2<BR>\n");

to make sure that it gives you what you want.

*********HTML*********

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="1"> A-Surface
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="2"> B-Surface
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="3"> Drawing
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="4"> Attachments
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>


<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="5"> P.I.S.T.
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="6"> Data Translation
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="7"> Engineering Change
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td>

<input type="checkbox" name="WORK_TYPE_ARRAY[]"value="8"> Feasibility
Date Required:<input name="TOW_DATEREQ_ARRAY[]" size=10 maxlength=10>
<BR>Instructions:<BR><TEXTAREA cols=50 rows=5 name="TOW_INST_ARRAY[]"></TEXTAREA></td><tr><td>


*******PHP***********

$numrows = count ($WORK_TYPE_ARRAY);

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

$j = $WORK_TYPE_ARRAY[$i] - 1;

$sql2 = "INSERT INTO tow_details (wo_id, tow_id, tow_datereq, tow_inst) VALUES
('$worknum', '$WORK_TYPE_ARRAY[$i]', '$TOW_DATEREQ_ARRAY[$j]', '$TOW_INST_ARRAY[$j]')";

$result2 = mysql_query($sql2) or die ("Query Failed");

}

Kelvin

bkatsma
Junior Member
posted June 22, 2000 11:41 AM     Click Here to See the Profile for bkatsma   Click Here to Email bkatsma     Edit/Delete Message Reply w/Quote
Thank you I tested and it look great!!!

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.