473,320 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UPDATE query not working correcty

monkeyjunky
I have written a database driven php program to keep up with inventory.
I added a field labeled 'box_num' into the existing database. Each entry has it's own id labeled 'id'. Each entry has one of two possible types, '20' or '30'.
My script runs two select queries, storing 'id' for each '20' entry in an array, and each '30' entry into a different array. I am then attempting to assign each entry a 'box_num' based upon its 'id' value. I am looping through the arrays as follows:
Expand|Select|Wrap|Line Numbers
  1. for ($x = 0; $x < count($twentyArray); $x++) {
  2.     $sql2 = ("UPDATE $db.boxes 
  3.            SET box_num = '".$twenty."'
  4.             WHERE id = '".$twentyArray[x]."'");           
  5.            $res2 = mysql_query($sql2) or die(mysql_error($mysql));
  6.         $twenty += 1;
  7.     }
  8.  
  9.     for ($y = 0; $y < count($thirtyArray); $y++) {
  10.     $sql3 = ("UPDATE $db.boxes 
  11.            SET box_num = '".$thirty."'
  12.             WHERE id = '".$thirtyArray[y]."'");           
  13.            $res3 = mysql_query($sql3) or die(mysql_error($mysql));
  14.         $thirty += 1;
  15.     }
  16.  
I am not getting any errors, but the query acts as if the WHERE clause is not even there. It assigns the same number to each entry. Through my debugging efforts I have deduced that:
1) The $twentyArray and $thirtyArray are being populated
2) The $twenty and $thirty values begin at 2000 and 3000, respectively. The loops are iterating through each variable, because when I echo the value of each variable at the end of the script, it prints the value increased by the correct number of entries for the specific type.
I can only assume that the problem is with my WHERE clause.
Does this make sense?
Can anyone help me?
Aug 13 '07 #1
3 1033
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. WHERE id = '".$twentyArray[x]."'"); 
You have missed the '$' off your 'x' and 'y' variables
Aug 13 '07 #2
Expand|Select|Wrap|Line Numbers
  1. WHERE id = '".$twentyArray[x]."'"); 
You have missed the '$' off your 'x' and 'y' variables
Holy Crap. I can't believe it.
Thanks.
Aug 13 '07 #3
pbmods
5,821 Expert 4TB
Merged duplicate threads.
Aug 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
3
by: Greg Strong | last post by:
Hello All, Is the only solution to an update query which requires the records in a certain order to dump the records into a temp table in the required order, then do the update query? I've...
7
by: aaron.kempf | last post by:
team so i have a nice little list in sharepoint.. about 15k items i've got the simplest little join statement in access; and im trying to UPDATE the sharepoint list via an access query. so...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
11
by: ZafT | last post by:
Hi all - thanks in advance for any help. I am trying to write a simple update script. In fact, I am re-using code that I've used before (successfully) but I can't figure out why it is not...
8
by: Andi Clemens | last post by:
Hi, I want to update our DNS servers periodically with some IP addresses. But I don't know how to do this. I searched the Internet quite a while but I haven't found a good example how to do...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.