Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

need help in php form submission code


211655

Recommended Posts

Posted

Hi i need some help.

i am writing this code which reads this form and then submits the value sin the database. i cant write the for loop or while loop for that.

 

now here whats i have

 

<td width="20"><INPUT NAME="itemname_1" TYPE="text" id="itemname_1" size="20"></td>
<td width="20"><INPUT NAME="itemmodel_1" TYPE="text" id="itemmodel_1" size="10"></td>
<td width="20"><INPUT NAME="itemprice_1" TYPE="text" id="itemprice_1" size="10"></td>
<td width="20"><input name="quantity_1" type="text"  id="quantity_1" size="10"></td>
<td width="20"><INPUT NAME="shippingcharge_1" TYPE="text"   id="shippingcharge_1" size="10"></td>
<td width="20"><INPUT NAME="ship_type_1" TYPE="text" id="ship_type_1" size="10"></td>

 

Now i have a plus button that adds a second set of lines similar to the code. it names each additional line of fields as itemname_2, itemsname_3 ..... and for all other fields.

 

 

now in my process page, i need to write a code that reads how many lines were added and then have a loop that puts them in the database.

 

any idea how do i do that.. i have code like that.

 

here $i < 5 = should be how many rows were added...

for ($i=1; $i<5; $i++) {
  
 $itemname . $i = $_POST['itemname_' . $i];
   $itemmodel . $i = $_POST['itemmode_' . $i];
   $itemprice . $i = $_POST['itemprice_' . $i];
   $ship_type . $i = $_POST['ship_type_' . $i];
   $shippingcharge. $i  = $_POST['shippingcharge_' . $i];
   $quantity . $i = $_POST['quantity_' . $i];
   /*
$orders_query5 = tep_db_query("insert into custom_orders_dtl
(c_id, c_product_name, c_product_model, c_product_price, c_shipping_price, c_product_quantity, c_shipping_type) 
values (\"$c_id2\", \"$itemname . $i \",\"$itemmodel . $i\", \"$itemprice . $i\", \"$shippingcharge . $i\", \"$quantity . $i\", \"$ship_type . $i\")
");

} 

 
   

 

it goes and just keep putting blank values in the database.. i think i m eithe rconcatenating wrong or have wrong code.

Posted

Your code won't work anyway - you don't need to try to declare separate variables for each item in your loop - drop the ". $i" off the end of your variable declarations and your SQL.

Posted

I've given you the answer already (see below)...

I'm not vouching for the SQL, since I don't know what you are doing with those "\" there...

 

 

for ($i=1; $i<5; $i++) {

 

$itemname = $_POST['itemname_' . $i];

$itemmodel = $_POST['itemmode_' . $i];

$itemprice = $_POST['itemprice_' . $i];

$ship_type = $_POST['ship_type_' . $i];

$shippingcharge = $_POST['shippingcharge_' . $i];

$quantity = $_POST['quantity_' . $i];

 

$orders_query5 = tep_db_query("insert into custom_orders_dtl

(c_id, c_product_name, c_product_model, c_product_price, c_shipping_price, c_product_quantity, c_shipping_type)

values (\"$c_id2\", \"$itemname\",\"$itemmodel\", \"$itemprice\", \"$shippingcharge\", \"$quantity\", \"$ship_type\")

");

 

}

Posted

There are several ways to approach the issue but the most logical is to pass the values as arrays and deal with them as such. Passing them as above and using that loop is grossly inefficient.

 

How are you creating the fields? Let's start there...

 

Bobby

Posted

<HTML>
<HEAD>

<script type="text/JavaScript">
function addRow(r){
var root = r.parentNode;//the root
var allRows = root.getElementsByTagName('tr');//the rows' collection
var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row
for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.length+1))
}
var cSel = cRow.getElementsByTagName('select')[0];
cSel.setAttribute('name',cSel.getAttribute('name')+'_'+(allRows.length+1));//change the selecet's name
root.appendChild(cRow);//appends the cloned row as a new row
}
function shownames(){
var allInp=document.getElementsByTagName('input');
for(var i=0;i<allInp.length;i++){
alert(allInp[i].name)
}
}
</script>
</HEAD>
<BODY>


<FORM name="form" ACTION="onlineorder_Process.php" METHOD="POST">

<FONT SIZE="-1"  color="red" FACE="Verdana, Arial, Helvetica, San-Serif"><B>All fields are REQUIRED</B>.</FONT>
	 <TABLE WIDTH="100%" BORDER="0" CELLSPACING="2" CELLPADDING="3">
                        
           
             <TR>
               <TD COLSPAN="2" BGCOLOR="#99CC66"><B><FONT COLOR="#ffffff" SIZE="-1"
                  FACE="Verdana, Arial, Helvetica, San-Serif">Billing Information</B> - Address exactly as it appears on your credit card statement</FONT></TD>
                
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Name</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Address</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="bname" TYPE="text"
                 SIZE="30"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="baddress" TYPE="text"
                 SIZE="30"></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">City</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">State</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="bcity" TYPE="text"
                 SIZE="30"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><input name="bstate" type="text" id="bstate" size="30"> </TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Zip/Postal
                 Code</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Country</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="bzipcode" TYPE="text"
                 SIZE="20"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><SELECT name="bcountry">
<OPTION>
<OPTION>United States</OPTION>
<OPTION>Canada</OPTION>
<OPTION>Afghanistan</OPTION>
<OPTION>Albania</OPTION>
<OPTION>Algeria</OPTION>
<OPTION>American Samoa</OPTION>
<OPTION>Andorra</OPTION>
<OPTION>Angola</OPTION>
<OPTION>Anguilla</OPTION>
<OPTION>Antarctica</OPTION>
<OPTION>Antigua and Barbuda</OPTION>
<OPTION>Argentina</OPTION>
<OPTION>Armenia</OPTION>
<OPTION>Aruba</OPTION>
<OPTION>Australia</OPTION>
<OPTION>Austria</OPTION>
<OPTION>Azerbaijan</OPTION>
<OPTION>Bahamas</OPTION>
<OPTION>Bahrain</OPTION>
<OPTION>Bangladesh</OPTION>
<OPTION>Barbados</OPTION>
<OPTION>Belarus</OPTION>
<OPTION>Belgium</OPTION>
<OPTION>Belize</OPTION>
<OPTION>Benin</OPTION>
<OPTION>Bermuda</OPTION>
<OPTION>Bhutan</OPTION>
<OPTION>Bolivia</OPTION>
<OPTION>Bosnia and Herzegovina</OPTION>
<OPTION>Botswana</OPTION>
<OPTION>Bouvet Island</OPTION>
<OPTION>Brazil</OPTION>
<OPTION>British Indian Ocean Terr</OPTION>
<OPTION>Brunei Darussalam</OPTION>
<OPTION>Bulgaria</OPTION>
<OPTION>Burkina Faso</OPTION>
<OPTION>Burundi</OPTION>
<OPTION>Cambodia</OPTION>
<OPTION>Cameroon</OPTION>
<OPTION>Cape Verde</OPTION>
<OPTION>Cayman Islands</OPTION>
<OPTION>Central African Republic</OPTION>
<OPTION>Chad</OPTION>
<OPTION>Chile</OPTION>
<OPTION>China, People\'s Republic of</OPTION>
<OPTION>Christmas Island</OPTION>
<OPTION>Cocos Islands</OPTION>
<OPTION>Colombia</OPTION>
<OPTION>Comoros</OPTION>
<OPTION>Congo</OPTION>
<OPTION>Cook Islands</OPTION>
<OPTION>Costa Rica</OPTION>
<OPTION>Cote D\'ivoire</OPTION>
<OPTION>Croatia</OPTION>
<OPTION>Cuba</OPTION>
<OPTION>Cyprus</OPTION>
<OPTION>Czech Republic</OPTION>
<OPTION>Denmark</OPTION>
<OPTION>Djibouti</OPTION>
<OPTION>Dominica</OPTION>
<OPTION>Dominican Republic</OPTION>
<OPTION>East Timor</OPTION>
<OPTION>Ecuador</OPTION>
<OPTION>Egypt</OPTION>
<OPTION>El Salvador</OPTION>
<OPTION>Equatorial Guinea</OPTION>
<OPTION>Eritrea</OPTION>
<OPTION>Estonia</OPTION>
<OPTION>Ethiopia</OPTION>
<OPTION>Falkland Islands</OPTION>
<OPTION>Faroe Islands</OPTION>
<OPTION>Fiji</OPTION>
<OPTION>Finland</OPTION>
<OPTION>France</OPTION>
<OPTION>France, Metropolitan</OPTION>
<OPTION>French Guiana</OPTION>
<OPTION>French Polynesia</OPTION>
<OPTION>French Southern Terr</OPTION>
<OPTION>Fyrom</OPTION>
<OPTION>Gabon</OPTION>
<OPTION>Gambia</OPTION>
<OPTION>Georgia</OPTION>
<OPTION>Germany</OPTION>
<OPTION>Ghana</OPTION>
<OPTION>Gibraltar</OPTION>
<OPTION>Greece</OPTION>
<OPTION>Greenland</OPTION>
<OPTION>Grenada</OPTION>
<OPTION>Guadeloupe</OPTION>
<OPTION>Guam</OPTION>
<OPTION>Guatemala</OPTION>
<OPTION>Guinea</OPTION>
<OPTION>Guinea-Bissau</OPTION>
<OPTION>Guyana</OPTION>
<OPTION>Haiti</OPTION>
<OPTION>Heard And Mcdonald Islands</OPTION>
<OPTION>Honduras</OPTION>
<OPTION>Hong Kong</OPTION>
<OPTION>Hungary</OPTION>
<OPTION>Iceland</OPTION>
<OPTION>India</OPTION>
<OPTION>Indonesia</OPTION>
<OPTION>Iran</OPTION>
<OPTION>Iraq</OPTION>
<OPTION>Ireland</OPTION>
<OPTION>Island de Waltz</OPTION>
<OPTION>Israel</OPTION>
<OPTION>Italy</OPTION>
<OPTION>Jamaica</OPTION>
<OPTION>Japan</OPTION>
<OPTION>Jordan</OPTION>
<OPTION>Kazakhstan</OPTION>
<OPTION>Kenya</OPTION>
<OPTION>Kiribati</OPTION>
<OPTION>Korea</OPTION>
<OPTION>Kuwait</OPTION>
<OPTION>Kyrgyzstan</OPTION>
<OPTION>Lao</OPTION>
<OPTION>Latvia</OPTION>
<OPTION>Lebanon</OPTION>
<OPTION>Lesotho</OPTION>
<OPTION>Liberia</OPTION>
<OPTION>Libyan Arab Jamahiriya</OPTION>
<OPTION>Liechtenstein</OPTION>
<OPTION>Lithuania</OPTION>
<OPTION>Luxembourg</OPTION>
<OPTION>Macau</OPTION>
<OPTION>Madagascar</OPTION>
<OPTION>Malawi</OPTION>
<OPTION>Malaysia</OPTION>
<OPTION>Maldives</OPTION>
<OPTION>Mali</OPTION>
<OPTION>Malta</OPTION>
<OPTION>Marshall Islands</OPTION>
<OPTION>Martinique</OPTION>
<OPTION>Mauritania</OPTION>
<OPTION>Mauritius</OPTION>
<OPTION>Mayotte</OPTION>
<OPTION>Mexico</OPTION>
<OPTION>Micronesia</OPTION>
<OPTION>Moldova</OPTION>
<OPTION>Monaco</OPTION>
<OPTION>Mongolia</OPTION>
<OPTION>Montserrat</OPTION>
<OPTION>Morocco</OPTION>
<OPTION>Mozambique</OPTION>
<OPTION>Myanmar</OPTION>
<OPTION>Namibia</OPTION>
<OPTION>Nauru</OPTION>
<OPTION>Nepal</OPTION>
<OPTION>Netherlands</OPTION>
<OPTION>Netherlands Antilles</OPTION>
<OPTION>New Caledonia</OPTION>
<OPTION>New Zealand</OPTION>
<OPTION>Nicaragua</OPTION>
<OPTION>Niger</OPTION>
<OPTION>Nigeria</OPTION>

<OPTION>Niue</OPTION>
<OPTION>Norfolk Island</OPTION>
<OPTION>Northern Mariana Islands</OPTION>
<OPTION>Norway</OPTION>
<OPTION>Oman</OPTION>
<OPTION>Pakistan</OPTION>
<OPTION>Palau</OPTION>
<OPTION>Panama</OPTION>
<OPTION>Papua New Guinea</OPTION>
<OPTION>Paraguay</OPTION>
<OPTION>Peru</OPTION>
<OPTION>Philippines</OPTION>
<OPTION>Pitcairn</OPTION>
<OPTION>Poland</OPTION>
<OPTION>Portugal</OPTION>
<OPTION>Puerto Rico</OPTION>
<OPTION>Qatar</OPTION>
<OPTION>Reunion</OPTION>
<OPTION>Romania</OPTION>
<OPTION>Russian Federation</OPTION>
<OPTION>Rwanda</OPTION>
<OPTION>Saint Helena</OPTION>
<OPTION>Saint Kitts and Nevis</OPTION>
<OPTION>Saint Lucia</OPTION>
<OPTION>Saint Pierre and Miquelon</OPTION>
<OPTION>Saint Vincent, The Grenadines</OPTION>
<OPTION>Samoa</OPTION>
<OPTION>San Marino</OPTION>
<OPTION>Sao Tome and Principe</OPTION>
<OPTION>Saudi Arabia</OPTION>
<OPTION>Senegal</OPTION>
<OPTION>Seychelles</OPTION>
<OPTION>Sierra Leone</OPTION>
<OPTION>Singapore</OPTION>
<OPTION>Slovakia</OPTION>
<OPTION>Slovenia</OPTION>
<OPTION>Solomon Islands</OPTION>
<OPTION>Somalia</OPTION>
<OPTION>South Africa</OPTION>
<OPTION>South Georgia</OPTION>
<OPTION>Spain</OPTION>
<OPTION>Sri Lanka</OPTION>
<OPTION>Sudan</OPTION>
<OPTION>Suriname</OPTION>
<OPTION>Svalbard and Jan Mayen</OPTION>
<OPTION>Swaziland</OPTION>
<OPTION>Sweden</OPTION>
<OPTION>Switzerland</OPTION>
<OPTION>Syrian Arab Republic</OPTION>
<OPTION>Taiwan</OPTION>
<OPTION>Tajikistan</OPTION>
<OPTION>Tanzania</OPTION>
<OPTION>Thailand</OPTION>
<OPTION>Togo</OPTION>
<OPTION>Tokelau</OPTION>
<OPTION>Tonga</OPTION>
<OPTION>Trinidad and Tobago</OPTION>
<OPTION>Tunisia</OPTION>
<OPTION>Turkey</OPTION>
<OPTION>Turkmenistan</OPTION>
<OPTION>Turks and Caicos Islands</OPTION>
<OPTION>Tuvalu</OPTION>
<OPTION>Uganda</OPTION>
<OPTION>Ukraine</OPTION>
<OPTION>United Arab Emirates</OPTION>
<OPTION>United Kingdom</OPTION>
<OPTION>Uruguay</OPTION>
<OPTION>Uzbekistan</OPTION>
<OPTION>Vanuatu</OPTION>
<OPTION>Vatican City State</OPTION>
<OPTION>Venezuela</OPTION>
<OPTION>Vietnam</OPTION>
<OPTION>Virgin Islands (British)</OPTION>
<OPTION>Virgin Islands (U.S.)</OPTION>
<OPTION>Wallis And Futuna Islands</OPTION>
<OPTION>Western Sahara</OPTION>
<OPTION>Yemen</OPTION>
<OPTION>Yugoslavia</OPTION>
<OPTION>Zaire</OPTION>
<OPTION>Zambia</OPTION>
<OPTION>Zimbabwe</OPTION>
</SELECT></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Phone
                 Number</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Email
                 Address</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="bphone" TYPE="text"
                 SIZE="20"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="bemail"
                 TYPE="text" SIZE="30"></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%"> </TD> 
               <TD WIDTH="50%"> </TD> 
             </TR>
             <TR>
               <TD COLSPAN="2" BGCOLOR="#99CC66"><B><FONT COLOR="#ffffff" SIZE="-1"
                  FACE="Verdana, Arial, Helvetica, San-Serif">Shipping Information</B> <input type="checkbox" name="copy" value="Yes" onClick="javascript:ShipToBillPerson(this.form);">  Check if same as billing information</FONT></TD>
                
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Name</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Address</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT name="sname" TYPE="text"
                 SIZE="30"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT name="saddress" TYPE="text"
                 SIZE="30"></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">City</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">State</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT name="scity" TYPE="text"
                 SIZE="30"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><input name="sstate" type="text" id="sstate" size="30"> </TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Zip/Postal
                 Code</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Country</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT name="szipcode" TYPE="text"
                 SIZE="20"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><SELECT name="scountry">
<OPTION>
<OPTION>United States</OPTION>
<OPTION>Canada</OPTION>
<OPTION>Afghanistan</OPTION>
<OPTION>Albania</OPTION>
<OPTION>Algeria</OPTION>
<OPTION>American Samoa</OPTION>
<OPTION>Andorra</OPTION>
<OPTION>Angola</OPTION>
<OPTION>Anguilla</OPTION>
<OPTION>Antarctica</OPTION>
<OPTION>Antigua and Barbuda</OPTION>
<OPTION>Argentina</OPTION>
<OPTION>Armenia</OPTION>
<OPTION>Aruba</OPTION>
<OPTION>Australia</OPTION>
<OPTION>Austria</OPTION>
<OPTION>Azerbaijan</OPTION>
<OPTION>Bahamas</OPTION>
<OPTION>Bahrain</OPTION>
<OPTION>Bangladesh</OPTION>
<OPTION>Barbados</OPTION>
<OPTION>Belarus</OPTION>
<OPTION>Belgium</OPTION>
<OPTION>Belize</OPTION>
<OPTION>Benin</OPTION>
<OPTION>Bermuda</OPTION>
<OPTION>Bhutan</OPTION>
<OPTION>Bolivia</OPTION>
<OPTION>Bosnia and Herzegovina</OPTION>
<OPTION>Botswana</OPTION>
<OPTION>Bouvet Island</OPTION>
<OPTION>Brazil</OPTION>
<OPTION>British Indian Ocean Terr</OPTION>
<OPTION>Brunei Darussalam</OPTION>
<OPTION>Bulgaria</OPTION>
<OPTION>Burkina Faso</OPTION>
<OPTION>Burundi</OPTION>
<OPTION>Cambodia</OPTION>
<OPTION>Cameroon</OPTION>
<OPTION>Cape Verde</OPTION>
<OPTION>Cayman Islands</OPTION>
<OPTION>Central African Republic</OPTION>
<OPTION>Chad</OPTION>
<OPTION>Chile</OPTION>
<OPTION>China, People\'s Republic of</OPTION>
<OPTION>Christmas Island</OPTION>
<OPTION>Cocos Islands</OPTION>
<OPTION>Colombia</OPTION>
<OPTION>Comoros</OPTION>
<OPTION>Congo</OPTION>
<OPTION>Cook Islands</OPTION>
<OPTION>Costa Rica</OPTION>
<OPTION>Cote D\'ivoire</OPTION>
<OPTION>Croatia</OPTION>
<OPTION>Cuba</OPTION>
<OPTION>Cyprus</OPTION>
<OPTION>Czech Republic</OPTION>
<OPTION>Denmark</OPTION>
<OPTION>Djibouti</OPTION>
<OPTION>Dominica</OPTION>
<OPTION>Dominican Republic</OPTION>
<OPTION>East Timor</OPTION>
<OPTION>Ecuador</OPTION>
<OPTION>Egypt</OPTION>
<OPTION>El Salvador</OPTION>
<OPTION>Equatorial Guinea</OPTION>
<OPTION>Eritrea</OPTION>
<OPTION>Estonia</OPTION>
<OPTION>Ethiopia</OPTION>
<OPTION>Falkland Islands</OPTION>
<OPTION>Faroe Islands</OPTION>
<OPTION>Fiji</OPTION>
<OPTION>Finland</OPTION>
<OPTION>France</OPTION>
<OPTION>France, Metropolitan</OPTION>
<OPTION>French Guiana</OPTION>
<OPTION>French Polynesia</OPTION>
<OPTION>French Southern Terr</OPTION>
<OPTION>Fyrom</OPTION>
<OPTION>Gabon</OPTION>
<OPTION>Gambia</OPTION>
<OPTION>Georgia</OPTION>
<OPTION>Germany</OPTION>
<OPTION>Ghana</OPTION>
<OPTION>Gibraltar</OPTION>
<OPTION>Greece</OPTION>
<OPTION>Greenland</OPTION>
<OPTION>Grenada</OPTION>
<OPTION>Guadeloupe</OPTION>
<OPTION>Guam</OPTION>
<OPTION>Guatemala</OPTION>
<OPTION>Guinea</OPTION>
<OPTION>Guinea-Bissau</OPTION>
<OPTION>Guyana</OPTION>
<OPTION>Haiti</OPTION>
<OPTION>Heard And Mcdonald Islands</OPTION>
<OPTION>Honduras</OPTION>
<OPTION>Hong Kong</OPTION>
<OPTION>Hungary</OPTION>
<OPTION>Iceland</OPTION>
<OPTION>India</OPTION>
<OPTION>Indonesia</OPTION>
<OPTION>Iran</OPTION>
<OPTION>Iraq</OPTION>
<OPTION>Ireland</OPTION>
<OPTION>Island de Waltz</OPTION>
<OPTION>Israel</OPTION>
<OPTION>Italy</OPTION>
<OPTION>Jamaica</OPTION>
<OPTION>Japan</OPTION>
<OPTION>Jordan</OPTION>
<OPTION>Kazakhstan</OPTION>
<OPTION>Kenya</OPTION>
<OPTION>Kiribati</OPTION>
<OPTION>Korea</OPTION>
<OPTION>Kuwait</OPTION>
<OPTION>Kyrgyzstan</OPTION>
<OPTION>Lao</OPTION>
<OPTION>Latvia</OPTION>
<OPTION>Lebanon</OPTION>
<OPTION>Lesotho</OPTION>
<OPTION>Liberia</OPTION>
<OPTION>Libyan Arab Jamahiriya</OPTION>
<OPTION>Liechtenstein</OPTION>
<OPTION>Lithuania</OPTION>
<OPTION>Luxembourg</OPTION>
<OPTION>Macau</OPTION>
<OPTION>Madagascar</OPTION>
<OPTION>Malawi</OPTION>
<OPTION>Malaysia</OPTION>
<OPTION>Maldives</OPTION>
<OPTION>Mali</OPTION>
<OPTION>Malta</OPTION>
<OPTION>Marshall Islands</OPTION>
<OPTION>Martinique</OPTION>
<OPTION>Mauritania</OPTION>
<OPTION>Mauritius</OPTION>
<OPTION>Mayotte</OPTION>
<OPTION>Mexico</OPTION>
<OPTION>Micronesia</OPTION>
<OPTION>Moldova</OPTION>
<OPTION>Monaco</OPTION>
<OPTION>Mongolia</OPTION>
<OPTION>Montserrat</OPTION>
<OPTION>Morocco</OPTION>
<OPTION>Mozambique</OPTION>
<OPTION>Myanmar</OPTION>
<OPTION>Namibia</OPTION>
<OPTION>Nauru</OPTION>
<OPTION>Nepal</OPTION>
<OPTION>Netherlands</OPTION>
<OPTION>Netherlands Antilles</OPTION>
<OPTION>New Caledonia</OPTION>
<OPTION>New Zealand</OPTION>
<OPTION>Nicaragua</OPTION>
<OPTION>Niger</OPTION>
<OPTION>Nigeria</OPTION>
<OPTION>Niue</OPTION>
<OPTION>Norfolk Island</OPTION>
<OPTION>Northern Mariana Islands</OPTION>
<OPTION>Norway</OPTION>
<OPTION>Oman</OPTION>
<OPTION>Pakistan</OPTION>
<OPTION>Palau</OPTION>
<OPTION>Panama</OPTION>
<OPTION>Papua New Guinea</OPTION>
<OPTION>Paraguay</OPTION>
<OPTION>Peru</OPTION>
<OPTION>Philippines</OPTION>
<OPTION>Pitcairn</OPTION>
<OPTION>Poland</OPTION>
<OPTION>Portugal</OPTION>
<OPTION>Puerto Rico</OPTION>
<OPTION>Qatar</OPTION>
<OPTION>Reunion</OPTION>
<OPTION>Romania</OPTION>
<OPTION>Russian Federation</OPTION>
<OPTION>Rwanda</OPTION>
<OPTION>Saint Helena</OPTION>
<OPTION>Saint Kitts and Nevis</OPTION>
<OPTION>Saint Lucia</OPTION>
<OPTION>Saint Pierre and Miquelon</OPTION>
<OPTION>Saint Vincent, The Grenadines</OPTION>
<OPTION>Samoa</OPTION>
<OPTION>San Marino</OPTION>
<OPTION>Sao Tome and Principe</OPTION>
<OPTION>Saudi Arabia</OPTION>
<OPTION>Senegal</OPTION>
<OPTION>Seychelles</OPTION>
<OPTION>Sierra Leone</OPTION>
<OPTION>Singapore</OPTION>
<OPTION>Slovakia</OPTION>
<OPTION>Slovenia</OPTION>
<OPTION>Solomon Islands</OPTION>
<OPTION>Somalia</OPTION>
<OPTION>South Africa</OPTION>
<OPTION>South Georgia</OPTION>
<OPTION>Spain</OPTION>
<OPTION>Sri Lanka</OPTION>
<OPTION>Sudan</OPTION>
<OPTION>Suriname</OPTION>
<OPTION>Svalbard and Jan Mayen</OPTION>
<OPTION>Swaziland</OPTION>
<OPTION>Sweden</OPTION>
<OPTION>Switzerland</OPTION>
<OPTION>Syrian Arab Republic</OPTION>
<OPTION>Taiwan</OPTION>
<OPTION>Tajikistan</OPTION>
<OPTION>Tanzania</OPTION>
<OPTION>Thailand</OPTION>
<OPTION>Togo</OPTION>
<OPTION>Tokelau</OPTION>
<OPTION>Tonga</OPTION>
<OPTION>Trinidad and Tobago</OPTION>
<OPTION>Tunisia</OPTION>
<OPTION>Turkey</OPTION>
<OPTION>Turkmenistan</OPTION>
<OPTION>Turks and Caicos Islands</OPTION>
<OPTION>Tuvalu</OPTION>
<OPTION>Uganda</OPTION>
<OPTION>Ukraine</OPTION>
<OPTION>United Arab Emirates</OPTION>
<OPTION>United Kingdom</OPTION>
<OPTION>Uruguay</OPTION>
<OPTION>Uzbekistan</OPTION>
<OPTION>Vanuatu</OPTION>
<OPTION>Vatican City State</OPTION>
<OPTION>Venezuela</OPTION>
<OPTION>Vietnam</OPTION>
<OPTION>Virgin Islands (British)</OPTION>
<OPTION>Virgin Islands (U.S.)</OPTION>
<OPTION>Wallis And Futuna Islands</OPTION>
<OPTION>Western Sahara</OPTION>
<OPTION>Yemen</OPTION>
<OPTION>Yugoslavia</OPTION>
<OPTION>Zaire</OPTION>
<OPTION>Zambia</OPTION>
<OPTION>Zimbabwe</OPTION>
</SELECT></TD> 
             </TR>
             
             <TR>
               <TD WIDTH="50%"> </TD> 
               <TD WIDTH="50%"> </TD> 
             </TR>
    
      <TR>
   <TD COLSPAN="2" BGCOLOR="#99CC66"><B><FONT COLOR="#ffffff" SIZE="-1"
                  FACE="Verdana, Arial, Helvetica, San-Serif">
   Product Info & Shipping</FONT></B></TD> 
             </TR>
          
<tr>
<FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">                 </FONT><P><FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, San-Serif"><strong>Price & Shipping Rates:</strong> Price & shipping rates are given to you by our staff. You need to enter the amount correctly. Wrong input will delay in processing your order. </FONT></TD> 


   
    </TR>
	 </table>  
    
<table border="0" width="500">
<tr>

<td span style="font-size:11px;"width="55">No.</td>
<td span style="font-size:11px;"width="80">           Item</td>
<td span style="font-size:11px;"width="50">                              Model</td>
<td span style="font-size:11px;"width="40">        Price</td>
<td span style="font-size:11px;"width="60">          Quantity</td>
<td span style="font-size:11px;"width="90">       Shipping</td>
<td span style="font-size:11px;"width="90">        Type</td>
<td span style="font-size:11px;"width="60"> </td>

</tr>
</table>

<table border="0" width="500">
<tr>

<td width="20"><select name="select">
       <option value="item1" selected="selected">item1</option>
       <option value="item2">item2</option>
       <option value="item3">item3</option>
       <option value="item4">item4</option>
       <option value="item5">item5</option>
 <option value="item5">item6</option>
 <option value="item5">item7</option>
 <option value="item5">item8</option>
 <option value="item5">item9</option>
 
 

     </select></td> 
<td width="20"><INPUT NAME="itemname_1" TYPE="text" id="itemname_1" size="20"></td>
<td width="20"><INPUT NAME="itemmodel_1" TYPE="text" id="itemmodel_1" size="10"></td>
<td width="20"><INPUT NAME="itemprice_1" TYPE="text" id="itemprice_1" size="10"></td>
<td width="20"><input name="quantity_1" type="text"  id="quantity_1" size="10"></td>
<td width="20"><INPUT NAME="shippingcharge_1" TYPE="text"   id="shippingcharge_1" size="10"></td>
<td width="20"><INPUT NAME="ship_type_1" TYPE="text" id="ship_type_1" size="10"></td>
<td width="20"><input name="button" type="button" style="background-color:99CC66;" value="+" onclick="addRow(this.parentNode.parentNode)"></td>

</tr>
</table>
  
  
  <table>
   
    <TR>
               <TD WIDTH="50%"> </TD> 
               <TD WIDTH="50%"> </TD> 
             </TR>
    
      <TR bgcolor="#99CC66">
               <TD COLSPAN="2" vlaign="middle"><B><FONT COLOR="#ffffff" SIZE="-1"
                  FACE="Verdana, Arial, Helvetica, San-Serif"><img src="/images/lockicon.gif" width="43" height="30" align="absmiddle">Secure Payment Information</B>     <a href="secureimage.jpg" target="blank"><u>(What is it?)</u></a></FONT></TD>
                
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Card
                 Holder Name</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Card
                 Type</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="cardholder" TYPE="text"
                 SIZE="30"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><SELECT NAME="cardtype">
                 <OPTION SELECTED value="">Choose One
                 <option value="Visa">Visa 
                 <option value="MasterCard">MasterCard 
                 <option value="Discover">Discover
                 <option value="American Express">American Express
                 </SELECT></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Card
                 Number</FONT></B></TD> 
               <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Expiration
                 Date</FONT></B></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="cardnumber" TYPE="text"
                 SIZE="30"></TD> 
               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="cardexp" TYPE="text" id="cardexp"
                 SIZE="30"></TD>
             </TR>
             <TR>
               <TD WIDTH="100%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">CVV Number</FONT></B></TD>
               <TD WIDTH="100%" BGCOLOR="#eeeeee"><B></B></TD>
             </TR>
             <TR>

               <TD WIDTH="50%" BGCOLOR="#ffffff"><INPUT NAME="cvv" TYPE="text" id="cvv"
                 SIZE="5">
               <br><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">The 3-digit security code found on the back of your card.</FONT></TD>
               <TD WIDTH="50%" BGCOLOR="#ffffff"> </TD>
             </TR>
             <TR>
               <TD WIDTH="50%"> </TD> 
               <TD WIDTH="50%"> </TD> 
             </TR>
    
    
             <TR>
               <TD COLSPAN="2" BGCOLOR="#99CC66"><B><FONT COLOR="#ffffff" SIZE="-1"
                  FACE="Verdana, Arial, Helvetica, San-Serif">Comments</B></FONT></TD>
                
             </TR>
             <TR>
               <TD COLSPAN="2" WIDTH="100%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, San-Serif">Comments and Special Instructions</FONT></B></TD>
             </TR>
             <TR>
               <TD COLSPAN="2" WIDTH="100%" BGCOLOR="#ffffff"><TEXTAREA NAME="comments"
                 ROWS="4" width="100%" COLS="85"></TEXTAREA></TD> 
             </TR>
             <TR>
               <TD WIDTH="50%"> </TD> 
               <TD WIDTH="50%"> </TD> 
             </TR>
 
 </TABLE>
	 
           
           

           <P><CENTER><INPUT TYPE="submit" VALUE="Confirm Order"></CENTER>
         </TD>
       </TR>
</FORM>
 
</BODY>
</HTML>

 

 

Now i just worry about the new lines i am adding. so name becomes '_n'

 

like itemname_1, itemname_2 etc.....

 

how would i read that how mnay lines they have added, and then how do i put them in database.

 

is there any eval function. i m good in coldfusion but php is kiiling me.. thanks

Posted

I wouldn't describe it as "grossly inefficient" - inelegant, yes, since the form input fields would be better defined as arrays, but the benefit would be minimal at best, since there is no way to write an array to a database without such a loop inserting row by row anyway, and the database inserts are the resource hogs.

Posted
I wouldn't describe it as "grossly inefficient" - inelegant, yes, since the form input fields would be better defined as arrays, but the benefit would be minimal at best, since there is no way to write an array to a database without such a loop inserting row by row anyway, and the database inserts are the resource hogs.

Grossly inefficient it is...

 

You cannot possible expect a finite loop to be scalable. It is best to pass the parameters as arrays and use a sizeof() check to form the loop limit. This will catch them all and be cleaner, faster, and more efficient.

 

With respect to resource hogs I have definitely seen worse offenders than a simple database insert...

 

Bobby

Posted
but how would i do that. any code ... i am totally stuck.... have no clue...

First, don't paste your HTML output of the page...it adds no value to see what was parsed.

 

Paste the PHP script that produced that HTML or better yet the relevant portions of that PHP script so as to keep this thread easier to follow / read.

 

Bobby

Posted

its simple html page that fills the values in the database.

i am ok with every thing. the only problem i have is to read the values from those new lines with naming convention and them put them in a loop along with insert statement.

 

any code help will be appreciated. i had posted the code above what i have currently. hope that will help what i m trying to get thanks

Posted

Let me finish this script I'm working on and I'll put something together for you...

 

Bobby

Posted

Bobby, inefficiency and scalabilty are totally different things - you should know that!

If fact, often the most efficient solutions are the least scalable...

 

Good luck with the script, I'm sure you'll come up with a good solution.

Posted

java script:

<script type="text/JavaScript">
function addRow(r){
var root = r.parentNode;//the root
var allRows = root.getElementsByTagName('tr');//the rows' collection
var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row
for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
//cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'['+(allRows.length+1)+']')
cInp[i].setAttribute('name',cInp[i].getAttribute('name'))
}
var cSel = cRow.getElementsByTagName('select')[0];
//cSel.setAttribute('name',cSel.getAttribute('name')+'['+(allRows.length+1)+']');//change the selecet's name
cSel.setAttribute('name',cSel.getAttribute('name'));//change the selecet's name
root.appendChild(cRow);//appends the cloned row as a new row
}
function shownames(){
var allInp=document.getElementsByTagName('input');
for(var i=0;i<allInp.length;i++){
alert(allInp[i].name)
}
}
</script>

HTML table:

    <table border="0" width="500">
       <tr>
           <td width="20"><select name="select[]">
                   <option value="item1" selected="selected">item1</option>
                   <option value="item2">item2</option>
                   <option value="item3">item3</option>
                   <option value="item4">item4</option>
                   <option value="item5">item5</option>
                   <option value="item5">item6</option>
                   <option value="item5">item7</option>
                   <option value="item5">item8</option>
                   <option value="item5">item9</option>
               </select></td>
           <td width="20"><INPUT NAME="itemname[]" TYPE="text" size="20"></td>
           <td width="20"><INPUT NAME="itemmodel[]" TYPE="text" size="10"></td>
           <td width="20"><INPUT NAME="itemprice[]" TYPE="text" size="10"></td>
           <td width="20"><input NAME="quantity[]" type="text"  size="10"></td>
           <td width="20"><INPUT NAME="shippingcharge[]" TYPE="text" size="10"></td>
           <td width="20"><INPUT NAME="ship_type[]" TYPE="text" size="10"></td>
           <td width="20"><input name="button" type="button" style="background-color:99CC66;" value="+" onclick="addRow(this.parentNode.parentNode)"></td>
       </tr>
   </table>

Submit form PHP (using tep API):

// Get the max number of passed rows
$limit = max( sizeof($_POST['select']), 
    sizeof($_POST['itemname']),
    sizeof($_POST['itemmodel']),
    sizeof($_POST['itemprice']),
    sizeof($_POST['quantity']),
    sizeof($_POST['shippingcharge']),
    sizeof($_POST['ship_type'])
    );

// Start the loop
$i = 0;
while ($i < $limit){
// Initialize the data array
$data_array = array( 'c_id' => $_POST['select'][$i],
      'c_product_name' => $_POST['itemname'][$i],
      'c_product_model' => $_POST['itemmodel'][$i],
      'c_product_price' => $_POST['itemprice'][$i],
      'c_shipping_price' => $_POST['shippingcharge'][$i],
      'c_product_quantity' => $_POST['quantity'][$i],
      'c_shipping_type' => $_POST['ship_type'][$i]
      );
// Insert the record
tep_db_perform('custom_orders_dtl', $data_array, 'insert');
// Increment loop by 1
$i++;
}

The form has been tested to create the rows and maintain the basic array structure. Also, the process logic has been tested to verify that it parses correctly. However, there are several areas that are not standard and will require your own skill at coding. For example, there is nothing to tie the products to an order_id or customer_id. Also, the select should have product_id's somewhere...

 

Basically, it is a working example of how to get it done and now you need to use the correct ID's, etc. to conform to tep API.

 

Bobby

Posted

Enjoy! Remember, it is far from being completed as there are areas that you need to implement to tie it into the osCommerce backend.

 

However, it shows the principles involved...

 

Bobby

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...