php-windows Digest 21 Jun 2013 05:08:45 -0000 Issue 4101

Topics (messages 31011 through 31014):

Re: Need help with mysql error
        31011 by: Jacob Kruger
        31012 by: Arno Kuhl
        31013 by: Gu®u

Re: [phpXperts] Re: [PHP-WIN] Need help with mysql error
        31014 by: shiplu

Administrivia:

To subscribe to the digest, e-mail:
        php-windows-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-windows-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-wind...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
What's the sort of final result version of $sql look like?

I am assuming that you're using something like sprintf function to build it
up based on original string, and values, etc.?

As in, I myself would generally have used something like $sql =
sprintf("insert into %s...", $tableName);

etc. - and that's a bastardised version to give you a better idea, and, the
easiest way to maybe try find out exactly what's causing the issue would be
to echo/spit out the whole $sql string value instead of trying to execute it
for now, followed by exit; or something like that to just see what the
resulting T-SQL statement would have been/contained.

That also brings up that when I insert/make use of form field values in
building an SQL statement, I would want to make sure they get processed by
mysqli_real_escape_string function - partly since I prefer using mysqli,
instead of just mysql, to make sure there are no funny characters in the
values as such.

The standard mysql real escape function is explained here:
http://php.net/manual/en/function.mysql-real-escape-string.php

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message ----- From: "Gu®u" <nagendra802...@gmail.com>
To: <php-wind...@lists.php.net>; "php mysql"
<php_mysql_usergr...@yahoogroups.com>; <phpexpe...@yahoogroups.com>
Sent: Friday, June 07, 2013 12:21 PM
Subject: [PHP-WIN] Need help with mysql error


Hi All,

I am working a a project in which there is a table with some variables. I
have a form with which I pull the filled data by user and want to put into
mysql dtabase. Below is my query.

$sql="INSERT INTO recipt (date, pt_name, age, od_sph, od_cyl, od_axis,
os_sph, os_cyl, os_axis, add, d_sph, od_d, od_n, od1, os1)
VALUES
('$_POST[date]','$_POST[pt_name]','$_POST[age]','$_POST[od_sph]','$_POST[od_cyl]','$_POST[od_axis]','$_POST[os_sph]','$_POST[os_cyl]','$_POST[os_axis]','$_POST[add]','$_POST[d_sph]','$_POST[od_d]','$_POST[od_n]','$_POST[od1]','$_POST[os1]')";

However I am getting an error saying:

Error: 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
'add, d_sph, od_d, od_n, od1, os1) VALUES ('12-12-2013','guru
prasad','23','12'' at line 1

I have tried gooling it but no luck. Please help me with this error.

Thank you in advance.

--
*Best,
*
*Gu®u
CEO & Founder at,
www.myshopads.com
*


--- End Message ---
--- Begin Message ---
-----Original Message-----
From: GuRu [mailto:nagendra802...@gmail.com] 
Sent: 07 June 2013 12:22 PM
To: php-wind...@lists.php.net; php mysql; phpexpe...@yahoogroups.com
Subject: [PHP-WIN] Need help with mysql error

Hi All,

I am working a a project in which there is a table with some variables. I
have a form with which I pull the filled data by user and want to put into
mysql dtabase. Below is my query.

$sql="INSERT INTO recipt (date, pt_name, age, od_sph, od_cyl, od_axis,
os_sph, os_cyl, os_axis, add, d_sph, od_d, od_n, od1, os1) VALUES
('$_POST[date]','$_POST[pt_name]','$_POST[age]','$_POST[od_sph]','$_POST[od_
cyl]','$_POST[od_axis]','$_POST[os_sph]','$_POST[os_cyl]','$_POST[os_axis]',
'$_POST[add]','$_POST[d_sph]','$_POST[od_d]','$_POST[od_n]','$_POST[od1]','$
_POST[os1]')";

However I am getting an error saying:

Error: 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
'add, d_sph, od_d, od_n, od1, os1) VALUES ('12-12-2013','guru
prasad','23','12'' at line 1

I have tried gooling it but no luck. Please help me with this error.

Thank you in advance.

--
*Best,
*
*GuRu
CEO & Founder at,
www.myshopads.com
*
==============================

Could "add" be a reserved word? Try a different column name and see if you
get the same error.

Cheers
Arno



--- End Message ---
--- Begin Message ---
Hi All,

Yes 'add' is a reserved word & that was my mistake. I was looking it from
PHP side all the time. I didn't thought about MYSQL stuff. I have changed
it to 'os_add' and now its working. Thanks guys. You guys rock :)




On Fri, Jun 7, 2013 at 8:47 PM, Arno Kuhl <a...@dotcontent.net> wrote:

> -----Original Message-----
> From: GuRu [mailto:nagendra802...@gmail.com]
> Sent: 07 June 2013 12:22 PM
> To: php-wind...@lists.php.net; php mysql; phpexpe...@yahoogroups.com
> Subject: [PHP-WIN] Need help with mysql error
>
> Hi All,
>
> I am working a a project in which there is a table with some variables. I
> have a form with which I pull the filled data by user and want to put into
> mysql dtabase. Below is my query.
>
> $sql="INSERT INTO recipt (date, pt_name, age, od_sph, od_cyl, od_axis,
> os_sph, os_cyl, os_axis, add, d_sph, od_d, od_n, od1, os1) VALUES
>
> ('$_POST[date]','$_POST[pt_name]','$_POST[age]','$_POST[od_sph]','$_POST[od_
>
> cyl]','$_POST[od_axis]','$_POST[os_sph]','$_POST[os_cyl]','$_POST[os_axis]',
>
> '$_POST[add]','$_POST[d_sph]','$_POST[od_d]','$_POST[od_n]','$_POST[od1]','$
> _POST[os1]')";
>
> However I am getting an error saying:
>
> Error: 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
> 'add, d_sph, od_d, od_n, od1, os1) VALUES ('12-12-2013','guru
> prasad','23','12'' at line 1
>
> I have tried gooling it but no luck. Please help me with this error.
>
> Thank you in advance.
>
> --
> *Best,
> *
> *GuRu
> CEO & Founder at,
> www.myshopads.com
> *
> ==============================
>
> Could "add" be a reserved word? Try a different column name and see if you
> get the same error.
>
> Cheers
> Arno
>
>
>


-- 
*Best,
*
*Gu®u
CEO & Founder at,
www.myshopads.com
*

--- End Message ---
--- Begin Message ---
On Jun 7, 2013 9:28 PM, "Gu®u" <nagendra802...@gmail.com> wrote:
>
>
>
> Hi All,
>
> Yes 'add' is a reserved word & that was my mistake. I was looking it from
PHP side all the time. I didn't thought about MYSQL stuff. I have changed
it to 'os_add' and now its working. Thanks guys. You guys rock :)
>

You can use reserved keywords as column names too.  Just use ` to enclose
the name. Like `add`

--- End Message ---

Reply via email to