SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Query Incompatible from Mysql 4.1.xx to 4.0.xx

    Hi all,

    I have the following query that is working fine in Mysql 4.1.xx but it ouputs the error when i uploaded it to my server which has only Mysql 4.0.xx

    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 '0= '0'-'0', NW= floor('46269'- '0'*(3*''+3*''+2*''+2*'')) WHERE


    The query is:
    PHP Code:
    $update_killspies=mysql_query("UPDATE users SET $the_m= '$set'-'$to_kill', NW= floor('$det[NW]'- '$to_kill'*(3*'$final_details[atk]'+3*'$final_details[def]'+2*'$final_details[spy]'+2*'$final_details[mage]')) WHERE Knumber='$det[Knumber]'",$link ) or die(mysql_error()); 
    Can anyone tell me what's wrong with this query in Mysql 4.0.xx ?

    Any help / comment will be appreciated. Thank you.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    you cannot set the value of the column called '0'

    most likely '0' isn't a valid column in your table

    you'll get this in any version of mysql
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Location
    San Diego, CA
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KCgame
    Hi all,

    I have the following query that is working fine in Mysql 4.1.xx but it ouputs the error when i uploaded it to my server which has only Mysql 4.0.xx

    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 '0= '0'-'0', NW= floor('46269'- '0'*(3*''+3*''+2*''+2*'')) WHERE

    The query is:
    PHP Code:
    $update_killspies=mysql_query("UPDATE users SET $the_m= '$set'-'$to_kill', NW= floor('$det[NW]'- '$to_kill'*(3*'$final_details[atk]'+3*'$final_details[def]'+2*'$final_details[spy]'+2*'$final_details[mage]')) WHERE Knumber='$det[Knumber]'",$link ) or die(mysql_error()); 
    Can anyone tell me what's wrong with this query in Mysql 4.0.xx ?
    It would appear that you have some variables that aren't being set properly, thus the zero values: $the_m, $set, $to_kill

    That logic is pretty painful to try and follow, so I'm not sure exactly what the formula should be. I like to break variables out of the string completely and use the . concatenation operator to glue the pieces together:

    PHP Code:
    $update_killspies mysql_query("UPDATE users SET $the_m=".
    (
    $set-$to_kill).
    ", NW=floor(".
    ((
    $det['NW'] - $to_kill) *
    (
    $final_details['atk'] +
     
    $final_details['def'] +
     
    $final_details['spy'] +
     
    $final_details['mage'])).
    ") WHERE Knumber=".$det['Knumber'], $link ) or
      die(
    mysql_error()); 
    or use sprintf placeholders:

    PHP Code:
    $query sprintf("UPDATE users SET %s=%s, NW=floor(%s) WHERE Knumber=%s",
    $the_m,
    (
    $set $to_kill),
    ((
    $det['NW'] - $to_kill) *
    (
    $final_details['atk'] +
     
    $final_details['def'] +
     
    $final_details['spy'] +
     
    $final_details['mage'])),
    $det['Knumber']);
    $update_killspies mysql_query($query$link) or
      die(
    mysql_error()); 
    Of course, none of these will work if your variables aren't being set properly before you try to use them.

  4. #4
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply..think i got the source of the problem..

    It is due to a logic error in my loop

    Thank for the help again^^


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •