Home > Archive > PHP Language > December 2005 > Field Number Limitation into MySQL
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Field Number Limitation into MySQL
|
|
|
| Is there a restriction to the number of fields you can work with in a
PHP to MySQL connection? I'd used as many as 15 quite a few times and
now I have a form with 34 fields and can't seem to get the info
inserted into the table even though I'm not getting any connection
errors, etc. Since my method is identical, I'm wondering if there's
some 'rule' I am unaware of. TIA
| |
| Mara Guida 2005-12-11, 6:59 pm |
| cover wrote:
> Is there a restriction to the number of fields you can work with in a
> PHP to MySQL connection? I'd used as many as 15 quite a few times and
> now I have a form with 34 fields and can't seem to get the info
> inserted into the table even though I'm not getting any connection
> errors, etc. Since my method is identical, I'm wondering if there's
> some 'rule' I am unaware of. TIA
GET vs POST? See the thread titled "Memory Limit for for HTML pages??"
| |
| Oli Filth 2005-12-11, 6:59 pm |
| Mara Guida said the following on 11/12/2005 17:31:
> cover wrote:
>
>
Just tried a 34-field insert; it worked fine.
What is your query string?
>
> GET vs POST? See the thread titled "Memory Limit for for HTML pages??"
>
This is completely unrelated.
--
Oli
| |
| Chuck Anderson 2005-12-11, 6:59 pm |
| cover wrote:
>Is there a restriction to the number of fields you can work with in a
>PHP to MySQL connection? I'd used as many as 15 quite a few times and
>now I have a form with 34 fields and can't seem to get the info
>inserted into the table even though I'm not getting any connection
>errors, etc. Since my method is identical, I'm wondering if there's
>some 'rule' I am unaware of. TIA
>
>
Put - echo mysql_error(); - right after your query.
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
| |
|
|
|
| On Sun, 11 Dec 2005 18:15:52 GMT, Oli Filth <catch@olifilth.co.uk>
wrote:
>
>Just tried a 34-field insert; it worked fine.
Hmmm. Guess I'll keep looking for an error.
>
>What is your query string?
>
$sqlquery = "INSERT INTO $table VALUES('$id', '$etype', '$area',
'$equipname', '$jdeno', '$equipno', '$mccloc', '$bspec', '$bsize',
'$bfpm', '$gbmanu', '$lube', '$gbsize', '$gbratio', '$motorsize',
'$motorframe', '$drivesprocket', '$drivensprocket', '$chainsize',
'$lacingtype', '$brgtypesize', '$brgqty', '$tbrgtypesize', '$tbrgqty',
'$headsize', '$hoawidth', '$tailsize', '$toawidth', '$cbsize',
'$keysize' '$uhmwsize', '$convnotes',)";
$results = mysql_query($sqlquery);
| |
|
| On Sun, 11 Dec 2005 12:11:02 -0700, Chuck Anderson
<websiteaddress@seemy.sig> wrote:
>Put - echo mysql_error(); - right after your query.
Thanks, I inserted it as follows:
$results = mysql_query($sqlquery);
echo mysql_error();
mysql_close();
and received the following error :
"Column count doesn't match value count at row 1"
looked at the database again and field lengths were okay to accomodate
variable content - thoughts?
| |
| Chris Hope 2005-12-11, 6:59 pm |
| cover wrote:
> On Sun, 11 Dec 2005 18:15:52 GMT, Oli Filth <catch@olifilth.co.uk>
> wrote:
>
>
> Hmmm. Guess I'll keep looking for an error.
>
>
> $sqlquery = "INSERT INTO $table VALUES('$id', '$etype', '$area',
> '$equipname', '$jdeno', '$equipno', '$mccloc', '$bspec', '$bsize',
> '$bfpm', '$gbmanu', '$lube', '$gbsize', '$gbratio', '$motorsize',
> '$motorframe', '$drivesprocket', '$drivensprocket', '$chainsize',
> '$lacingtype', '$brgtypesize', '$brgqty', '$tbrgtypesize', '$tbrgqty',
> '$headsize', '$hoawidth', '$tailsize', '$toawidth', '$cbsize',
> '$keysize' '$uhmwsize', '$convnotes',)";
There's a comma before the closing bracket. I would say that's your
error. echo mysql_error() after running the query and see what happens.
Or alternatively echo out the sql string and paste it into the mysql
console or phpMyAdmin etc.
One other thing, where do all those values come from? Directly from the
form with no escaping? If so, you need to read up on the topic of sql
injection.
And one other thing... I personally believe you are better to write your
insert query in the form:
INSERT INTO tablename (fieldname1, fieldname2, ... ) VALUES ('value1',
'value2', ...)
than not specity the fieldnames. Sure, it takes time to write your
query, but if you add a column to the table at a later time you will
break any existing insert queries for that table as the number of
columns specified in your query won't match the number in the table.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
| |
| Chris Hope 2005-12-11, 6:59 pm |
| cover wrote:
> On Sun, 11 Dec 2005 12:11:02 -0700, Chuck Anderson
> <websiteaddress@seemy.sig> wrote:
>
>
>
> Thanks, I inserted it as follows:
> $results = mysql_query($sqlquery);
> echo mysql_error();
> mysql_close();
>
> and received the following error :
> "Column count doesn't match value count at row 1"
>
> looked at the database again and field lengths were okay to accomodate
> variable content - thoughts?
It means you have eg 35 columns in your database but your sql string
only has values for 34 of them. See the other message I just posted a
couple of minutes ago.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
| |
|
| On Mon, 12 Dec 2005 10:20:59 +1300, Chris Hope
<blackhole@electrictoolbox.com> wrote:
>There's a comma before the closing bracket. I would say that's your
>error. echo mysql_error() after running the query and see what happens.
>Or alternatively echo out the sql string and paste it into the mysql
>console or phpMyAdmin etc.
caught the comma after installing the echo mysql_error(); line and now
have:
"You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'x 2" x .25', 'no notes')' at line 1" unless I remove the
measurements from the uhmwsize field which were 60' x 2" x .25"*
after blanking that field, the error came back to a more simple
"Column count doesn't match value count at row 1" which now makes me
wonder... Setting id as an integer when establishing the database,
what numerical entry should I enter into that?
>One other thing, where do all those values come from? Directly from the
>form with no escaping? If so, you need to read up on the topic of sql
>injection.
I use two forms to enter the data and until now, it's worked very well
(so far with fields of 12 or less). One form is the user input, the
second does the query and insert while echoing the values to the
screen of what the user just entered into the database.
>And one other thing... I personally believe you are better to write your
>insert query in the form:
>
>INSERT INTO tablename (fieldname1, fieldname2, ... ) VALUES ('value1',
>'value2', ...)
I've done it this way too - kind of got away from it which may have
been bad however, went back to it for this error solving and it made
no difference in the outcome or error.
>
>than not specity the fieldnames. Sure, it takes time to write your
>query, but if you add a column to the table at a later time you will
>break any existing insert queries for that table as the number of
>columns specified in your query won't match the number in the table.
| |
|
| Still having the "Column count doesn't match value count at row 1"
error - what a pain in the backside...
| |
| Hilarion 2005-12-12, 8:01 am |
| >>There's a comma before the closing bracket. I would say that's your
>
> caught the comma after installing the echo mysql_error(); line and now
> have:
> "You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near 'x 2" x .25', 'no notes')' at line 1" unless I remove the
> measurements from the uhmwsize field which were 60' x 2" x .25"*
>
> after blanking that field, the error came back to a more simple
> "Column count doesn't match value count at row 1" which now makes me
> wonder... Setting id as an integer when establishing the database,
> what numerical entry should I enter into that?
>
>
> I use two forms to enter the data and until now, it's worked very well
> (so far with fields of 12 or less). One form is the user input, the
> second does the query and insert while echoing the values to the
> screen of what the user just entered into the database.
>
>
> I've done it this way too - kind of got away from it which may have
> been bad however, went back to it for this error solving and it made
> no difference in the outcome or error.
You definitely have to read about value escaping and SQL injection.
One (or more) of the values you are placing in your query contains
apostrophe sign. This makes query which looks like that:
$qry = "INSERT INTO tablename VALUES ( '$some_value' )"
look like that (for $some_value == "John's deep"):
INSERT INTO tablename VALUES 'John's deep'
The apostrophe contained in the value is recognized as the string value
terminator. This causes syntax error in this case. If the user notices
that he's values break the script, then he can realize that your
script is vulnerable to SQL injection and enter value which will
make $some_value == "'; DROP TABLE tablename;" which in turn will make
the query look like this:
INSERT INTO tablename VALUES ''; DROP TABLE tablename;
which will make the insert and drop the table.
Again, as Chris suggested: read about SQL injection and start using
functions like "mysql_real_escape_string".
Hilarion
| |
| Christopher Pomasl 2005-12-13, 7:59 am |
| On Sun, 11 Dec 2005 13:01:28 -0800, cover wrote:
> On Sun, 11 Dec 2005 18:15:52 GMT, Oli Filth <catch@olifilth.co.uk>
> wrote:
>
>
> Hmmm. Guess I'll keep looking for an error.
>
>
> $sqlquery = "INSERT INTO $table VALUES('$id', '$etype', '$area',
> '$equipname', '$jdeno', '$equipno', '$mccloc', '$bspec', '$bsize',
> '$bfpm', '$gbmanu', '$lube', '$gbsize', '$gbratio', '$motorsize',
> '$motorframe', '$drivesprocket', '$drivensprocket', '$chainsize',
> '$lacingtype', '$brgtypesize', '$brgqty', '$tbrgtypesize', '$tbrgqty',
> '$headsize', '$hoawidth', '$tailsize', '$toawidth', '$cbsize',
> '$keysize' '$uhmwsize', '$convnotes',)";
>
> $results = mysql_query($sqlquery);
Someone already noted the extra comma at the end before the close paren.
You are also, seemingly, missing a comma between keisize and uhmwsize in
the last line.
Also take heed about the unescaped variables, if that is the case.
Someone savvy enough could all sorts of fun stuff to your SQL execution.
I also always print the error along with the error SQL in the event of an
error. If the user gets it on their page, well, they weren't going
anywhere anyway and you have the diagnostics when they complain!!
Chris
Always remember, you are unique...just like everyone else.
| |
| Norman Peelman 2005-12-14, 7:55 am |
| cover,
I'm only counting 32 values in your query string (apart from the other
errors already noted) and you are stating you are doing a 34 value insert...
Norm
--
FREE Avatar hosting at www.easyavatar.com
"cover" <coverlandNOSPAM914@yahoo.com> wrote in message
news:kohpp11dp93huqrvju6srft6vrv0jsujqh@
4ax.com...
> Still having the "Column count doesn't match value count at row 1"
> error - what a pain in the backside...
| |
| Norman Peelman 2005-12-14, 7:55 am |
| "cover" <coverlandNOSPAM914@yahoo.com> wrote in message
news:0ugpp11dp93huqrvju6srft6vrv0jsujbh@
4ax.com...
> On Mon, 12 Dec 2005 10:20:59 +1300, Chris Hope
> <blackhole@electrictoolbox.com> wrote:
>
>
>
> caught the comma after installing the echo mysql_error(); line and now
> have:
> "You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near 'x 2" x .25', 'no notes')' at line 1" unless I remove the
> measurements from the uhmwsize field which were 60' x 2" x .25"*
>
Mix-matched quotes is what's happening here - the (" double quote) is
signaling php the end of the string and it is truncating the rest of your
query. Like Hilarion said, check out escaping strings -
mysql_real_escape_string() or make sure to read up on magicquotes in your
php.ini file.
http://us3.php.net/manual/en/functi...cape-string.php <-
prefered method according to the link below
http://us3.php.net/magic_quotes/
Norm
---
FREE Avatar hosting at www.easyavatar.com
|
|
|
|
|