Jump to content

[SOLVED] Duplicate queries with code instead of hardcoding?


Recommended Posts

I have a gigantic script that updates a database with posted variables. The code is too large to post here in the message so I made it into a text file here:

 

http://ainventory.com/pages/po_update_submit.php.txt

 

It is nearly 2MB in size and its mostly duplicate code, I would save it instead of clicking it and view it in notepad or something as it is pretty large for a browser. It was working before I added all the duplicate code, I think it is too big to function now. I have checked it for coding errors in phpdesigner and there is none, but before when it only had 3 items with 1-25 updates on each it worked, when I duplicated them out to 20 items with 1-50 updates on each it is not working and seems to stop loading a few seconds into loading. There should be some way to duplicate those rows without having them typed out the way they are. Any ideas?

I have a database I need to update with duplicate data but on their own individual rows, so it is taking data from a form, using a multiplier (1,2,3,etc. all the way to 50) and taking the insert query and running it x amount of times for each item (x is the multiplier).

I think you have to re-think your requirements. Why do you need duplicate data in your database?

 

If you really need this, it can all be done with loops and arrays if your form is coded properly. Please post the source of your form.

 

Ken

<table width="800" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="360" align="center" valign="top">
<font style="font-size: 1em;" face="Tahoma"><b>
GLOBAL RESTAURANT<br>
EQUIPMENT AND SUPPLIES, INC.<br>
</font>
<font style="font-size: 0.8em;" face="Tahoma">
LEASING &#149; SALES &#149; EXPORT &#149; REPAIRS</b><br>
650 N.W. 123rd Street &#149; Miami, Florida 33168<br>
Office: (305) 688-8700 &#149; Fax: (305) 688-9455
</font>
</td>
<td width="80">
<td>
<td width="360">
<table width="360">
<tr>
<td width="120">
</td>
<td width="230">
<font style="font-size: 1.3em;" face="Tahoma"><b>
<center>PURCHASE ORDER    </b>
</font>
<br>
</center>
<form name="clientForm" action="http://<?=$_SERVER['HTTP_HOST']?>/pages/po_update_submit.php" method="post">
<div style="padding-left:3px;padding-top:4px; padding-bottom:4px; ">
<input type="text" name="new_po_number" class="po_number" value="<?=$po_number?>" READONLY  onFocus="this.blur()" size="25">
</div>
<font style="font-size: 0.7em;" face="Tahoma">
THIS NUMBER MUST APPEAR ON INVOICES, B/L, BUNDLES, CASES,PACKING LIST, AND CORRESPONDENCE. 
</td>
</tr>
</table>
</td>
</tr>
</table>

<br>

<table width="800" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="360">
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
<tr>
<td width="360">
<font style="font-size: 0.9em;" face="Tahoma">
<center><b>VENDOR</b></center>
</font>
</td>
</tr>
</table>
<?
$sql_vendor = "SELECT * FROM `vendor_database` WHERE `vendor_code`='$vendor_code' LIMIT 1";
$query_vendor = mysql_query($sql_vendor);
while($vendor_row = mysql_fetch_array($query_vendor)){
$vendor_code = $vendor_row['vendor_code'];
$vendor_name = $vendor_row['vendor_name'];
$vendor_saddress = $vendor_row['vendor_saddress'];
$vendor_saddress2 = $vendor_row['vendor_saddress2'];
$vendor_city = $vendor_row['vendor_city'];
$vendor_state = $vendor_row['vendor_state'];
$vendor_zip = $vendor_row['vendor_zip'];
$vendor_country = $vendor_row['vendor_country'];
$vendor_phone = $vendor_row['vendor_phone'];
$vendor_fax = $vendor_row['vendor_fax'];
$vendor_contact = $vendor_row['vendor_contact'];
$ise_vendor = $vendor_row['ise_vendor'];
$edit_record = $vendor_row['edit_record'];
$shipto_links = $vendor_row['shipto_links'];
$vendor_csz =$vendor_city.", ".$vendor_state.", ".$vendor_zip;
}
?>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
NAME:</font> <input type="text" name="vendor_name" id="vendor_name" class="text_input" value="<?=$vendor_name?>" READONLY  onFocus="this.blur()" size="60">
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
ADDRESS:</font> <input type="text" name="vendor_address" id="vendor_address" class="text_input" value="<?=$vendor_saddress?>" READONLY  onFocus="this.blur()" size="57">

</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
CITY,STATE,ZIP:</font> <input type="text" name="vendor_csz" id="vendor_csz" class="text_input" value="<?=$vendor_csz?>" READONLY  onFocus="this.blur()" size="50">
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
PHONE:</font> <input type="text" name="vendor_phone" id="vendor_phone" class="text_input" value="<?=$vendor_phone?>" READONLY  onFocus="this.blur()" size="59">
</font>
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
FAX:</font> <input type="text" name="vendor_fax" id="vendor_fax" class="text_input" value="<?=$vendor_fax?>" READONLY  onFocus="this.blur()" size="61">
</td>
</tr>
</table>
</td>
<td width="80">
</td>
<td width="360">
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
<tr>
<td width="360">
<font style="font-size: 0.9em;" face="Tahoma">
<center><b>SHIP TO:</b></center>
</font>
</td>
</tr>
</table>
<?
$sql_shipto = "SELECT * FROM `shipto_database` WHERE `shipto_code`='$shipto_code' LIMIT 1";
$query_shipto = mysql_query($sql_shipto);
while($shipto_row = mysql_fetch_array($query_shipto)){
$shipto_code = $shipto_row['shipto_code'];
$shipto_name = $shipto_row['shipto_name'];
$shipto_saddress = $shipto_row['shipto_saddress'];
$shipto_saddress2 = $shipto_row['shipto_saddress2'];
$shipto_city = $shipto_row['shipto_city'];
$shipto_state = $shipto_row['shipto_state'];
$shipto_zip = $shipto_row['shipto_zip'];
$shipto_country = $shipto_row['shipto_country'];
$shipto_phone = $shipto_row['shipto_phone'];
$shipto_fax = $shipto_row['shipto_fax'];
$shipto_contact = $shipto_row['shipto_contact'];
$shipto_bol = $shipto_row['shipto_bol'];
$edit_record = $shipto_row['edit_record'];
$shipto_csz = $shipto_city.", ".$shipto_state.", ".$shipto_zip;
}
?>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
NAME:</font> <input type="text" name="ship_to_name" id="ship_to_name" class="text_input" value="<?=$shipto_name?>" READONLY  onFocus="this.blur()" size="59">
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
ADDRESS:</font> <input type="text" name="ship_to_address" id="ship_to_address" class="text_input" value="<?=$shipto_saddress?>" READONLY  onFocus="this.blur()" size="57">
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
CITY,STATE,ZIP:</font> <input type="text" name="ship_to_csz" id="ship_to_csz" class="text_input" value="<?=$shipto_csz?>" READONLY  onFocus="this.blur()" size="49">
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
PHONE:</font> <input type="text" name="ship_to_phone" id="ship_to_phone" class="text_input" value="<?=$shipto_phone?>" READONLY  onFocus="this.blur()" size="58">
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
CONTACT:</font> <input type="text" name="ship_to_contact" id="ship_to_contact" class="text_input" value="<?=$shipto_contact?>" READONLY  onFocus="this.blur()" size="56">
</td>
</tr>
</table>
</td>
</tr>
</table>

<br>

<table width="800" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="150">
<table width="150" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 1px;">
<tr>
<td width="150" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
 DATE OF ORDER
</font>
</td>
</tr>
<tr>
<td width="150" height="20">
<div style="padding-left:3px;">
<input type="text" name="date_of_order" class="text_input" value="<?=$order_date?>" READONLY  onFocus="this.blur()" size="25">
</div>
</td>
</tr>
</table>
</td>
<td width="150">
<table width="150" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="150" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
 DATE WANTED
</font>
</td>
</tr>
<tr>
<td width="150" height="20">
<div style="padding-left:3px;">
<input type="text" name="date_wanted" class="text_input" value="<?=$date_wanted?>" READONLY  onFocus="this.blur()" size="25">
</div>
</td>
</tr>
</table>
</td>
<td width="100">
<table width="100" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="100" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
 ISE NUMBER
</font>
</td>
</tr>
<tr>
<td width="100" height="20">
<div style="padding-left:3px;">
<input type="text" name="ise_number" class="text_input" value="<?=$ise_number?>" READONLY  onFocus="this.blur()" size="15">
</div>
</td>
</tr>
</table>
</td>
<td width="200">
<table width="200" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="200" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
 ACCOUNT NUMBER
</font>
</td>
</tr>
<tr>
<td width="200" height="20">
<div style="padding-left:3px;">
<input type="text" name="account_number" class="text_input" value="<?=$account_number?>" READONLY  onFocus="this.blur()" size="35">
</div>
</td>
</tr>
</table>
</td>
<td width="200">
<table width="200" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="200" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
 SHIP VIA
</font>
</td>
</tr>
<tr>
<td width="200" height="20">
<div style="padding-left:3px;">
<input type="text" name="ship_via" class="text_input" value="<?=$ship_via?>" READONLY  onFocus="this.blur()" size="35">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="670" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="69">
<table width="69" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 1px;"
<tr>
<td width="69" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>RECEIVED</center>
</font>
</td>
</tr>
</table>
</td>
<td width="64">
<table width="64" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 1px;"
<tr>
<td width="64" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>AMOUNT</center>
</font>
</td>
</tr>
</table>
</td>
<td width="89">
<table width="89" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 1px;"
<tr>
<td width="89" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>ITEM NUMBER</center>
</font>
</td>
</tr>
</table>
</td>
<td width="349">
<table width="349" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="349" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>DESCRIPTION</center>
</font>
</td>
</tr>
</table>
</td>
<td width="78">
<table width="78" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="78" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>QUANTITY</center>
</font>
</td>
</tr>
</table>
</td>
<td width="71">
<table width="71" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="71" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>PRICE</center>
</font>
</td>
</tr>
</table>
</td>
<td width="80">
<table width="80" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="80" height="10" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
<center>TOTAL AMOUNT</center>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>


<?
$sql_po_items = "SELECT * FROM `purchase_order` WHERE `po_number`='$po_number'";
$query_po_items = mysql_query($sql_po_items);
while($po_items = mysql_fetch_array($query_po_items)){
$variable_num = $variable_num+1;
?>
<table width="670" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="69">
<table width="69" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 1px;"
<tr>
<td width="69" height="22" align="left">
<center>
<font style="font-size: 0.7em;" face="Tahoma">
<input  class="text_input" onCheck="makeTxt('box_<?=$variable_num?>', '<?=$po_items['quantity']?>');" onUnCheck="makeTxt('box_<?=$variable_num?>', '');" type="checkbox" name="item_number_checkbox_<?=$variable_num?>" value="<?=$po_items['item_number']?>">
</font>
</center>
</td>
</tr>
</table>
</td>
<td width="64">
<table width="64" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 1px;"
<tr>
<td width="64" height="22" align="left" valign="middle">
<center>
<textarea class="text_input" rows="1" cols="2" name="box_<?=$variable_num?>" id="box_<?=$variable_num?>" style="height:14px;width:50px;"></textarea>
</center>
</td>
</tr>
</table>
</td>
<td width="89">
<table width="89" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 1px;"
<tr>
<td width="89" height="22" align="left">
<div style="padding-left:3px;">
<input type="text" name="item_number_<?=$variable_num?>" class="text_input" value="<?=$po_items['item_number']?>" READONLY  onFocus="this.blur()" size="12">
</div>
</td>
</tr>
</table>
</td>
<td width="349">
<table width="349" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="349" height="22" align="left">
<div style="padding-left:3px;">
<input type="text" name="description_<?=$variable_num?>" class="text_input" value="<?=$po_items['name']?>" READONLY  onFocus="this.blur()" size="50">
</div>
</td>
</tr>
</table>
</td>
<td width="78">
<table width="78" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="78" height="22" align="left">
<div style="padding-left:3px;">
<input type="text" name="quantity_<?=$variable_num?>" class="text_input" value="<?=$po_items['quantity']?>" READONLY  onFocus="this.blur()" size="5">
</div>
</td>
</tr>
</table>
</td>
<td width="70">
<table width="70" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="70" height="22" align="left">
<div style="padding-left:3px;">
<input type="text" name="price_<?=$variable_num?>" class="text_input" size="10" value="<?=$po_items['item_cost']?>" READONLY  onFocus="this.blur()">
</div>
</td>
</tr>
</table>
</td>
<td width="80">
<table width="80" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:1px; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px;">
<tr>
<td width="80" height="22" align="left">
<?
$item_total = $po_items['item_cost']*$po_items['quantity'];
?>
<div style="padding-left:3px;">
<input type="text" name="line_total_<?=$variable_num?>" class="text_input" value="<?=$item_total?>" READONLY  onFocus="this.blur()" size="10">
<input type="hidden" name="manufacturer_<?=$variable_num?>" value="<?=$po_items['manufacturer']?>">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
}
?>
<br><br>
<table width="800" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="360">
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
<tr>
<td width="360">
<font style="font-size: 0.9em;" face="Tahoma">

</font>
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 1px; border-bottom-width: 0px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
ORDERED BY
</font>
</td>
</tr>
</table>
</td>
<td width="80">
</td>
<td width="360">
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
<tr>
<td width="360">
<font style="font-size: 0.9em;" face="Tahoma">

</font>
</td>
</tr>
</table>
<table width="360" cellspacing="0" cellpadding="0" border="0" bordercolor="black" style="border-right-width:0px; border-top-width: 1px; border-bottom-width: 0px; border-left-width: 0px;">
<tr>
<td width="360" align="left">
<font style="font-size: 0.7em;" face="Tahoma">
AUTHORIZED BY
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

Isn't there a way I can, under each if box_1 == , box_1 == 2 , box_1 ==3, etc. I can insert some code that makes rows of data, counting them, until it reaches a number, like 50 ( run until x > 50 ), so it writes out that some code over and over until it reaches that number?

 

Say for example you wanted your php code to write the numbers for pagination, but only wanted to go as high as 10 , you would have some type of coding that would start the count, display the numbers, and stop when it reached 10, instead of numbers couldn't this be anything? Coding, html, images, etc?

 

If so, how would you do that, I can use that and can shrink down the size of the script severely.

There has to be a way to do this. Lets do something simple:

 

I want to print the word cat on the screen x number of times, I am going to let a variable posted to the page determine how many times it is posted. So the page would be printcat.php?x=7 which would mean to print it 7 times.

 

What would be the code for duplicating a line via a variable number of times based on a posted variable?

Here's how I would do this (untested). BTW, as your code is now written, it looks like you're depending on register_globals to be enabled. This is a very bad assumption on your part.

<?php
for ($i = 1; $i < 21; $i++) { // loop for the number of $item_number
   if ($_POST['item_number_' . $i] != '') {
      $q = "SELECT * FROM products_description WHERE model_number='" . mysql_real_escape_string($_POST['item_number_checkbox_' . $i]) . "'";
      $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
      $row = mysql_fetch_assoc($result); 
      $descriptions = $row['description'];
      $query="INSERT INTO inventory (manufacturer,model_no,name,description,condition,po_number,received_date,edit_record,location,scan_code) VALUES ('" . mysql_real_escape_string($_POST['manufacturer_' . $i] . "','" . mysql_real_escape-string($_POST['item_number_' . $i] . "','" . mysql_real_escape_string($_POST['description_' . $i] . "','$descriptions','New','$new_po_number','$received_date','$name','Undefined','Undefined')";
      for ($j = 1;$j <= $_POST['box_' . $i];$j++) {
           $result=mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error());
      }
   }
}
?>

 

Ken

 

 

Thanks Ken, that looks just like what I need, except it is giving me an error ( syntax error unexpected ',' ) when I check it with phpdesigner, it wouldn't run on the site, so I checked it to see whats wrong, its on line 13 somewhere. Its in one of the mysql_real_escape_strings i.e.:

 

 '" . mysql_real_escape_string($_POST['manufacturer_' . $i] . "' 

 

I think it is something to do with where the ' . $i] ."' part is at, but I cannnot tell. Can you figure it out?

 

Thanks!

I missed putting in the closing ")":

<?php
'" . mysql_real_escape_string($_POST['manufacturer_' . $i]) . "'
?>

 

It's quite possible that there are other syntax errors in the code, since I didn't check it.

 

Ken

Yes, that was it. It is not breaking anymore but it isn't posting anything. I checked using an echo in different spots, it is getting to row 1 but ends there, it only ouputs two number 1's using the below code. It never gets to the post 'box_' I am pretty sure the problem is in this area:

 

     for ($j = 1; $j <= $_POST['box_' . $i]; $j++) {

 

But I can't figure out. Wouldn't that be looking for a number with no text (i.e. no box_1, box_2 but just 1 or 2)? for whatever reason it stops the code right there. Any ideas? Below is what I used to test where it was stoping at:

 

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$received_date = date("m|d|Y");
$dateandtime = date("YmdHis" ,time());
?>
<?php
for ($i = 1; $i < 21; $i++) { // loop for the number of $item_number
   if ($_POST['item_number_' . $i] != '') {
      $q = "SELECT * FROM products_description WHERE model_number='" . mysql_real_escape_string($_POST['item_number_checkbox_' . $i]) . "'";
      $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
      $row = mysql_fetch_assoc($result); 
      $descriptions = $row['description'];
echo "1";
echo "<br>";
echo $i;
      $query="INSERT INTO inventory (manufacturer,model_no,name,description,condition,po_number,received_date,edit_record,location,scan_code) VALUES ('" . mysql_real_escape_string($_POST['manufacturer_' . $i]) . "','" . mysql_real_escape-string($_POST['item_number_' . $i]) . "','" . mysql_real_escape_string($_POST['description_' . $i]) . "','$descriptions','New','$new_po_number','$received_date','$name','Undefined','Undefined')";
      for ($j = 1; $j <= $_POST['box_' . $i]; $j++) {
echo "1";
echo "<br>";
echo $j;
           $result=mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error());
      }
   }
}
?>

Array
(
    [new_po_number] => 10000001-100050001
    [vendor_name] => DISPENSE-RITE
    [vendor_address] => 2205 CARLSON DRIVE
    [vendor_csz] => NORTHBROOK, IL, 60062
    [vendor_phone] => 847-753-9595
    [vendor_fax] => 1-847-753-9648
    [ship_to_name] => Global Restaurant Equipment and Supplies, Inc.
    [ship_to_address] => 650 NW 123rd ST
    [ship_to_csz] => MIAMI, FL, 33168
    [ship_to_phone] => 305-688-8700
    [ship_to_contact] => CASEY RAJA
    [date_of_order] => 09|11|2008
    [date_wanted] => 09|11|2008
    [ise_number] => 5437112
    [account_number] => 223344
    [ship_via] => UPS
    [item_number_checkbox_1] => JT20-A8450
    [box_1] => 3
    [item_number_1] => JT20-A8450
    [description_1] => (A8450) Jet Spray Cold Beverage Dispenser JT20
    [quantity_1] => 3
    [price_1] => 951.99
    [line_total_1] => 2855.97
    [manufacturer_1] => Cornelius
    [item_number_checkbox_2] => 17BC-SC
    [box_2] => 7
    [item_number_2] => 17BC-SC
    [description_2] => ELECTRIC PASTA SYSTEMS
    [quantity_2] => 7
    [price_2] => 1242.23
    [line_total_2] => 8695.61
    [manufacturer_2] => Frymaster
    [item_number_checkbox_3] => 174CBA
    [box_3] => 1
    [item_number_3] => 174CBA
    [description_3] => BROIL-O-DOGS
    [quantity_3] => 1
    [price_3] => 845.37
    [line_total_3] => 845.37
    [manufacturer_3] => Star Mfg
)

 

Those are the results. Any ideas?

 

Thanks again, I appreciate it!

I just tried removing the loop at the bottom, for the number of $results runs to perform, so it would always do one regardless, and it didn't update. So it is stopping somewhere in the $query area. Here is what I used and it doesn't post to the database:

 

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$received_date = date("m|d|Y");
$dateandtime = date("YmdHis" ,time());
?>
<?php
for ($i = 1; $i < 21; $i++) { // loop for the number of $item_number
   if ($_POST['item_number_' . $i] != '') {
      $q = "SELECT * FROM products_description WHERE model_number='" . mysql_real_escape_string($_POST['item_number_checkbox_' . $i]) . "'";
      $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
      $row = mysql_fetch_assoc($result); 
      $descriptions = $row['description'];
      $query="INSERT INTO inventory (manufacturer,model_no,name,description,condition,po_number,received_date,edit_record,location,scan_code) VALUES ('" . mysql_real_escape_string($_POST['manufacturer_' . $i]) . "','" . mysql_real_escape-string($_POST['item_number_' . $i]) . "','" . mysql_real_escape_string($_POST['description_' . $i]) . "','$descriptions','New','$new_po_number','$received_date','$name','Undefined','Undefined')" or die("Problem with the query: $q<br>" . mysql_error());
           $result=mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error());
   }
}
?>

 

Any ideas?

Here's a test script using the $_POST array values you showed, with just some debugging echos instead of the mysql functions. It seems to be looping correctly.

<?php
$_POST = Array
(
    'new_po_number' => '10000001-100050001',
    'vendor_name' => 'DISPENSE-RITE',
    'vendor_address' => '2205 CARLSON DRIVE',
    'vendor_csz' => 'NORTHBROOK, IL, 60062',
    'vendor_phone' => '847-753-9595',
    'vendor_fax' => '1-847-753-9648',
    'ship_to_name' => 'Global Restaurant Equipment and Supplies, Inc.',
    'ship_to_address' => '650 NW 123rd ST',
    'ship_to_csz' => 'MIAMI, FL, 33168',
    'ship_to_phone' => '305-688-8700',
    'ship_to_contact' => 'CASEY RAJA',
    'date_of_order' => '09|11|2008',
    'date_wanted' => '09|11|2008',
    'ise_number' => '5437112',
    'account_number' => '223344',
    'ship_via' => 'UPS',
    'item_number_checkbox_1' => 'JT20-A8450',
    'box_1' => '3',
    'item_number_1' => 'JT20-A8450',
    'description_1' => '(A8450) Jet Spray Cold Beverage Dispenser JT20',
    'quantity_1' => '3',
    'price_1' => '951.99',
    'line_total_1' => '2855.97',
    'manufacturer_1' => 'Cornelius',
    'item_number_checkbox_2' => '17BC-SC',
    'box_2' => '7',
    'item_number_2' => '17BC-SC',
    'description_2' => 'ELECTRIC PASTA SYSTEMS',
    'quantity_2' => '7',
    'price_2' => '1242.23',
    'line_total_2' => '8695.61',
    'manufacturer_2' => 'Frymaster',
    'item_number_checkbox_3' => '174CBA',
    'box_3' => '1',
    'item_number_3' => '174CBA',
    'description_3' => 'BROIL-O-DOGS',
    'quantity_3' => '1',
    'price_3' => '845.37',
    'line_total_3' => '845.37',
    'manufacturer_3' => 'Star Mfg'
);
for ($i = 1; $i < 21; $i++) { // loop for the number of $item_number
   if (isset($_POST['item_number_' . $i]) && $_POST['item_number_' . $i] != '') {
	echo "\$_POST['item_number_" . $i . "'] = " . $_POST['item_number_' . $i] . "<br>\n";
	echo "\$_POST['box_" . $i . "'] = " . $_POST['box_' . $i] . "<br>\n";
      for ($j = 1; $j <= $_POST['box_' . $i]; $j++) {
			echo $j . "<br>\n";
      }
   }
}
?>

 

Ken

Yes, I was trying some things on my end and found the problem is somewhere here:

 

      $query="INSERT INTO inventory (manufacturer,model_no,name,description,condition,po_number,received_date,edit_record,location,scan_code) VALUES ('" . mysql_real_escape_string($_POST['manufacturer_' . $i]) . "','" . mysql_real_escape-string($_POST['item_number_' . $i]) . "','" . mysql_real_escape_string($_POST['description_' . $i]) . "','$descriptions','New','$new_po_number','$received_date','$name','Undefined','Undefined')" or die("Problem with the query: $q<br>" . mysql_error());

 

When I left that as is it posted nothing and the query did not break or die, but when I removed the mysql_real_scape strings it worked, but it isn't posting the variables, it is just posting verabatim like this:

 

$_POST[manufacturer_1]

 

Which is exactly what posts to the database, the value is that text in the code box, not the actual variable just the text as it is shown there. I can't figure it out. Any ideas? We almost have it, it is right there with just one thing missing...

I put in the echo's again before the $query and after the $query, after the $query no echo's are displayed, before it they are, and it never loops beyond 1, so whatever is wrong is right there. here is the code I used to find that out:

 

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>
<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$received_date = date("m|d|Y");
$dateandtime = date("YmdHis" ,time());
?>
<?php
for ($i = 1; $i < 21; $i++) { // loop for the number of $item_number
   if ($_POST['item_number_' . $i] != '') {
      $q = "SELECT * FROM products_description WHERE model_number='" . mysql_real_escape_string($_POST['item_number_checkbox_' . $i]) . "'";
      $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
      $row = mysql_fetch_assoc($result); 
      $descriptions = $row['description'];
echo "1";
echo "<br>";
echo $i;
echo "<br>";
echo "before query: ".$_POST['quantity_' . $i];
$x = $_POST['quantity_' . $i];
      $query="INSERT INTO inventory (manufacturer,model_no,name,description,condition,po_number,received_date,edit_record,location,scan_code) VALUES ('" . mysql_real_escape_string($_POST['manufacturer_' . $i]) . "','" . mysql_real_escape-string($_POST['item_number_' . $i]) . "','" . mysql_real_escape_string($_POST['description_' . $i]) . "','$descriptions','New','$new_po_number','$received_date','$name','Undefined','Undefined')";
      for ($j = 1; $j = $x; $j++) {
echo "1";
echo "<br>";
echo "j: ".$j;
echo "<br>";
echo "x: ".$x;

           $result=mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error());
      }
   }
}
?>

 

 

One thing I did figure out was we were using box_$i when it is quantity_$i we needed to use.

 

Any ideas what is wrong in the query or why it doesn't make it past the query or run the query?

 

Here is the final, 100% working code:

 

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$received_date = date("m|d|Y");
$dateandtime = date("YmdHis" ,time());
?>
<?php
for ($i = 1; $i < 21; $i++) { // loop for the number of $item_number
   if ($_POST['item_number_checkbox_' . $i] != '') {
      $q = "SELECT * FROM products_description WHERE model_number='" . mysql_real_escape_string($_POST['item_number_checkbox_' . $i]) . "'";
      $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
      $row = mysql_fetch_assoc($result); 
      $descriptions = $row['description'];
$z = $_POST['box_' . $i];
$x = $z+1;
      $query="INSERT INTO inventory (manufacturer,model_no,name,description,condition,po_number,received_date,edit_record,location,scan_code) VALUES ('" . mysql_real_escape_string($_POST['manufacturer_' . $i]) . "','" . mysql_real_escape_string($_POST['item_number_' . $i]) . "','" . mysql_real_escape_string($_POST['description_' . $i]) . "','$descriptions','New','$new_po_number','$received_date','$name','Undefined','Undefined')";
      for ($j = 1; $j < $x; $j++) {
           $result=mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error());
      }
   }
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.