473,320 Members | 1,699 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.

strange behaviour using arrays to update records

Hello
Im having problems working out why the following code does not work. I dont
think its the sql as the error occurs on the first update which ever one is
put there ($q1 or $q2). Ive swapped then around to test this.
Help greatly appreciated

The error is Unknown column 'A' in 'field list'
but there is no field 'A'. im thinking that the 'A' may be first letter of
the word Array, as if it is using this as a variable, but i dont know how.
$commindexarray=$_POST['commindex'];
$catarray=addslashes($_POST['category']);
$commarray=addslashes($_POST['comm']);
$availarray=$_POST['avail'];
$delarray=$_POST['del'];

if($delarray==''){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$q2 ="UPDATE usercomms SET typeid={$catarray[$i]} WHERE userid=
".$_SESSION['userid']." AND commindex ={$commindexarray[$i]}";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid={$catarray[$i]}, comment='{$commarray[$i]}',
available={$availarray[$i]}, timestp='$currtime', globalavail=0 WHERE
commindex={$commindexarray[$i]}";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

}
}
Aug 7 '06 #1
8 1590
mantrid wrote:
Hello
Im having problems working out why the following code does not work. I dont
think its the sql as the error occurs on the first update which ever one is
put there ($q1 or $q2). Ive swapped then around to test this.
Help greatly appreciated

The error is Unknown column 'A' in 'field list'
but there is no field 'A'. im thinking that the 'A' may be first letter of
the word Array, as if it is using this as a variable, but i dont know how.
$commindexarray=$_POST['commindex'];
$catarray=addslashes($_POST['category']);
$commarray=addslashes($_POST['comm']);
$availarray=$_POST['avail'];
$delarray=$_POST['del'];

if($delarray==''){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$q2 ="UPDATE usercomms SET typeid={$catarray[$i]} WHERE userid=
".$_SESSION['userid']." AND commindex ={$commindexarray[$i]}";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid={$catarray[$i]}, comment='{$commarray[$i]}',
available={$availarray[$i]}, timestp='$currtime', globalavail=0 WHERE
commindex={$commindexarray[$i]}";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

}
}

Non-numeric constants MUST be enclosed in single quotes in your SQL
statements. Otherwise they may be taken as a column name.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 7 '06 #2
"mantrid" <ia********@virgin.netwrote:
Im having problems working out why the following code does not work. I dont
think its the sql as the error occurs on the first update which ever one is
put there ($q1 or $q2). Ive swapped then around to test this.
Help greatly appreciated

The error is Unknown column 'A' in 'field list'
but there is no field 'A'. im thinking that the 'A' may be first letter of
the word Array, as if it is using this as a variable, but i dont know how.
$commindexarray=$_POST['commindex'];
$catarray=addslashes($_POST['category']);
$commarray=addslashes($_POST['comm']);
$availarray=$_POST['avail'];
$delarray=$_POST['del'];

if($delarray==''){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$q2 ="UPDATE usercomms SET typeid={$catarray[$i]} WHERE userid=
".$_SESSION['userid']." AND commindex ={$commindexarray[$i]}";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid={$catarray[$i]}, comment='{$commarray[$i]}',
available={$availarray[$i]}, timestp='$currtime', globalavail=0 WHERE
commindex={$commindexarray[$i]}";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

}
}
PHP is not Perl. If you call addslashes() on an array, it treats it as a
string, which means it has the value "Array". Then, when $i == 0 and you
look at $catarray[$i], you get the first character, which is 'A'.

You need to iterate through your arrays and call addslashes on each
element individually. The most efficient way would be to move the
addslashes (or perhaps mysql_real_escape_string instead) inside the $i
for loop that you already have:

for ($i = 0; $i < count($commindexarray); $i++)
{
$cat = intval($_POST['category'][$i]);
$comm = mysql_real_escape_string($_POST['comm'][$i]);
$q = "update usercomms
set type = {$cat},
comm = {$comm}
where whatever";
}

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 7 '06 #3
"mantrid" <ia********@virgin.netwrote in message
news:aN********************@newsfe6-gui.ntli.net...
Hello
Im having problems working out why the following code does not work. I
dont
think its the sql as the error occurs on the first update which ever one
is
put there ($q1 or $q2). Ive swapped then around to test this.
Help greatly appreciated

The error is Unknown column 'A' in 'field list'
but there is no field 'A'. im thinking that the 'A' may be first letter of
the word Array, as if it is using this as a variable, but i dont know how.
$commindexarray=$_POST['commindex'];
$catarray=addslashes($_POST['category']);
$commarray=addslashes($_POST['comm']);
$availarray=$_POST['avail'];
$delarray=$_POST['del'];

if($delarray==''){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$q2 ="UPDATE usercomms SET typeid={$catarray[$i]} WHERE userid=
".$_SESSION['userid']." AND commindex ={$commindexarray[$i]}";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid={$catarray[$i]},
comment='{$commarray[$i]}',
available={$availarray[$i]}, timestp='$currtime', globalavail=0 WHERE
commindex={$commindexarray[$i]}";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

}
}

Not to mention that you are intermixing two styles of string
concatination... try:

$q2 ="UPDATE usercomms SET typeid={$catarray[$i]} WHERE
userid={$_SESSION['userid']} AND commindex ={$commindexarray[$i]}";

Norm
--
FREE Avatar hosting at www.easyavatar.com
Aug 7 '06 #4
Ive made the changes you suggested. I dont get any errors now but the
records are not updating. It is most puzzling. My updated code is below
************************************************** **************************
*****
$delarray=$_POST['del'];//not needed in the sql of first two queries so isnt
in for loop

if(count($delarray)==0){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$cat = intval($_POST['category'][$i]);
$comm = mysql_real_escape_string($_POST['comm'][$i]);
$avail =$_POST['avail'][$i];
$commindex = intval($_POST['commindex'][$i]);

$q2 ="UPDATE usercomms SET typeid=$cat WHERE userid=".$_SESSION['userid']."
AND commindex =$commindex";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid=$cat, comment='$comm', available=$avail,
timestp='$currtime', globalavail=0 WHERE commindex=$commindex";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');
}
}

************************************************** **********************

Im also getting the following warning (below) on the bottom of the page. It
isnt affecting anything as it also appears with other queries I run on this
page which do work. Does anyone know what causes it. I dont think I can
follow its suggestion for not displaying it as I dont think I can alter any
settings on my hosting companies server. if that is what its asking me to
do.

Warning: Unknown(): Your script possibly relies on a session side-effect
which existed until PHP 4.2.3. Please be advised that the session extension
does not consider global variables as a source of data, unless
register_globals is enabled. You can disable this functionality and this
warning by setting session.bug_compat_42 or session.bug_compat_warn to off,
respectively. in Unknown on line 0

THANKS Ian
"Miguel Cruz" <sp**@admin.u.nuwrote in message
news:spam-6605DF.14173407082006@localhost...
"mantrid" <ia********@virgin.netwrote:
Im having problems working out why the following code does not work. I
dont
think its the sql as the error occurs on the first update which ever one
is
put there ($q1 or $q2). Ive swapped then around to test this.
Help greatly appreciated

The error is Unknown column 'A' in 'field list'
but there is no field 'A'. im thinking that the 'A' may be first letter
of
the word Array, as if it is using this as a variable, but i dont know
how.


$commindexarray=$_POST['commindex'];
$catarray=addslashes($_POST['category']);
$commarray=addslashes($_POST['comm']);
$availarray=$_POST['avail'];
$delarray=$_POST['del'];

if($delarray==''){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$q2 ="UPDATE usercomms SET typeid={$catarray[$i]} WHERE userid=
".$_SESSION['userid']." AND commindex ={$commindexarray[$i]}";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid={$catarray[$i]},
comment='{$commarray[$i]}',
available={$availarray[$i]}, timestp='$currtime', globalavail=0 WHERE
commindex={$commindexarray[$i]}";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

}
}

PHP is not Perl. If you call addslashes() on an array, it treats it as a
string, which means it has the value "Array". Then, when $i == 0 and you
look at $catarray[$i], you get the first character, which is 'A'.

You need to iterate through your arrays and call addslashes on each
element individually. The most efficient way would be to move the
addslashes (or perhaps mysql_real_escape_string instead) inside the $i
for loop that you already have:

for ($i = 0; $i < count($commindexarray); $i++)
{
$cat = intval($_POST['category'][$i]);
$comm = mysql_real_escape_string($_POST['comm'][$i]);
$q = "update usercomms
set type = {$cat},
comm = {$comm}
where whatever";
}

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu

Aug 7 '06 #5
"mantrid" <ia********@virgin.netwrote:
Ive made the changes you suggested. I dont get any errors now but the
records are not updating. It is most puzzling. My updated code is below
************************************************** **************************
*****
$delarray=$_POST['del'];//not needed in the sql of first two queries so isnt
in for loop

if(count($delarray)==0){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$cat = intval($_POST['category'][$i]);
$comm = mysql_real_escape_string($_POST['comm'][$i]);
$avail =$_POST['avail'][$i];
$commindex = intval($_POST['commindex'][$i]);

$q2 ="UPDATE usercomms SET typeid=$cat WHERE userid=".$_SESSION['userid']."
AND commindex =$commindex";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid=$cat, comment='$comm', available=$avail,
timestp='$currtime', globalavail=0 WHERE commindex=$commindex";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');
}
}
I would print out $q and $q2 to ensure that $_SESSION['userid'] contains
what you thought it does.

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 7 '06 #6

*****
$delarray=$_POST['del'];//not needed in the sql of first two queries so
isnt
in for loop

if(count($delarray)==0){
for ($i = 0; $i < count($commindexarray); $i++){
$currtime=date('YmdHis');
$cat = intval($_POST['category'][$i]);
$comm = mysql_real_escape_string($_POST['comm'][$i]);
$avail =$_POST['avail'][$i];
$commindex = intval($_POST['commindex'][$i]);

$q2 ="UPDATE usercomms SET typeid=$cat WHERE
userid=".$_SESSION['userid']."
AND commindex =$commindex";//
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry, there was a problem updating. Try
again.<br><br>Error - 1 '.count($delarray). mysql_error().'</span>');
$q="UPDATE comments SET typeid=$cat, comment='$comm', available=$avail,
timestp='$currtime', globalavail=0 WHERE commindex=$commindex";//
$updatecomm = mysql_query($q) or die('<br><span class=RedWarning>Sorry,
there was a problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');
}
}

I would print out $q and $q2 to ensure that $_SESSION['userid'] contains
what you thought it does.
This I did and it is as expected,
Another thing I tried was to put the queries outside of the loop and
substitute the values from the arrays (which are also ok as i checked them
when i ran phpinfo()) with numbers as shown below
$q2 ="UPDATE usercomms SET typeid=1 WHERE userid=".$_SESSION['userid']." AND
commindex =339";
$updateusercomm = mysql_query($q2) or die('<br><span class=RedWarning>Sorry,
there was a problem updating. Try again.<br><br>Error - 1
'.count($delarray). mysql_error().'</span>');

$q="UPDATE comments SET typeid=1, comment='ggdsffgdsfg', available=1,
timestp='$currtime', globalavail=0 WHERE commindex=339"; $updatecomm =
mysql_query($q) or die('<br><span class=RedWarning>Sorry, there was a
problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

And this worked. so it looks like it is the loop or something

by the way miguel I like your photos. i to love travelling but havent put
mine on the web, something i'd like to do. much of mine are still on paper
so a lot of work to do.

Ian


Aug 7 '06 #7
>
This I did and it is as expected,
Another thing I tried was to put the queries outside of the loop and
substitute the values from the arrays (which are also ok as i checked them
when i ran phpinfo()) with numbers as shown below
$q2 ="UPDATE usercomms SET typeid=1 WHERE userid=".$_SESSION['userid']."
AND
commindex =339";
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry,
there was a problem updating. Try again.<br><br>Error - 1
'.count($delarray). mysql_error().'</span>');

$q="UPDATE comments SET typeid=1, comment='ggdsffgdsfg', available=1,
timestp='$currtime', globalavail=0 WHERE commindex=339"; $updatecomm =
mysql_query($q) or die('<br><span class=RedWarning>Sorry, there was a
problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

And this worked. so it looks like it is the loop or something

by the way miguel I like your photos. i to love travelling but havent put
mine on the web, something i'd like to do. much of mine are still on paper
so a lot of work to do.

Ian


ok getting closer. it is this bit

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

i tested it with the following and it worked on those 100 records

for ($i = 0; $i <= 100; $i += 1){
ian
Aug 7 '06 #8
ok i got it
silly me
i hade commented out the setting of the variable

$commindexarray=$_POST['commindex'];
THANKS ALL for the help
"mantrid" <ia********@virgin.netwrote in message
news:gt*****************@newsfe6-win.ntli.net...
>

This I did and it is as expected,
Another thing I tried was to put the queries outside of the loop and
substitute the values from the arrays (which are also ok as i checked
them
when i ran phpinfo()) with numbers as shown below
$q2 ="UPDATE usercomms SET typeid=1 WHERE userid=".$_SESSION['userid']."
AND
commindex =339";
$updateusercomm = mysql_query($q2) or die('<br><span
class=RedWarning>Sorry,
there was a problem updating. Try again.<br><br>Error - 1
'.count($delarray). mysql_error().'</span>');

$q="UPDATE comments SET typeid=1, comment='ggdsffgdsfg', available=1,
timestp='$currtime', globalavail=0 WHERE commindex=339"; $updatecomm =
mysql_query($q) or die('<br><span class=RedWarning>Sorry, there was a
problem updating some records. Try again.<br><br>Error - 2
'.count($delarray).mysql_error().'</span>');

And this worked. so it looks like it is the loop or something

by the way miguel I like your photos. i to love travelling but havent
put
mine on the web, something i'd like to do. much of mine are still on
paper
so a lot of work to do.

Ian


ok getting closer. it is this bit

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

i tested it with the following and it worked on those 100 records

for ($i = 0; $i <= 100; $i += 1){
ian


Aug 7 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason | last post by:
Currently I have a number of html forms which loop through records in a database table. In order to be able to update the right record when the form is submitted, I've tacked number on to the...
0
by: Phil | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
9
by: Kevin Hodgson | last post by:
I'm experiencing a strange Dataset Update problem with my application. I have a dataset which has a table holding a set of customer information records. (address, contact, info, etc.) I have a...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
4
by: mantrid | last post by:
Im using arrays generated from my records displayed in a table on my site to update the corresponding records in a mysql database ie on the web page col1 col2 col3 1 2 2 1 ...
2
by: Aggelos | last post by:
Hello, I am trying to export/import about 50.000 records in a csv file which a user can upload or downlaod from the browser. The problem is once I hit export Firefox comes with a dowload...
0
by: charmeda103 | last post by:
when i run my program it runs with no erorrs but the output screen is giving me strange results here is whats its giving me: CONFERENCE OVERALL RANK TEAM W-L % WINS MARGIN W-L ...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.