1
miscade
mysql_query(UPDATE... performing arithmetic calculations...
  • 2005/3/24 15:17

  • miscade

  • Just popping in

  • Posts: 18

  • Since: 2005/2/18


having a strange behaviour from a MySQL UPDATE.

- assuming set1 is defined as a 'text' in the MySQL table

- assuming $set1 is "3-1",

after doing a
$result = mysql_query("UPDATE $data SET set1 = $set1 WHERE numg = $numg");

the content of the set1 field will become 2 (3 minus 1).

Anybody knows how to avoid this and let UPDATE treat the string as text, not calculating the content?



2
Mithrandir
Re: mysql_query(UPDATE... performing arithmetic calculations...

$result $xoopsDB->query("UPDATE $data SET set1 = ".$xoopsDB->quoteString($set1)." WHERE numg = ".intval($numg));

Always sanitize your variables before using them in an SQL statement.

3
miscade
Re: mysql_query(UPDATE... performing arithmetic calculations...
  • 2005/3/24 16:05

  • miscade

  • Just popping in

  • Posts: 18

  • Since: 2005/2/18


Quote:

Mithrandir wrote:
$result $xoopsDB->query("UPDATE $data SET set1 = ".$xoopsDB->quoteString($set1)." WHERE numg = ".intval($numg));

Always sanitize your variables before using them in an SQL statement.


Thanks, it works as expected...

I'm quite newby for some of these aspects. Could you give me a quick explanation of how this makes the right job?

Rgds
_______________
Miscade

Login

Who's Online

322 user(s) are online (272 user(s) are browsing Support Forums)


Members: 0


Guests: 322


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits