grlayouts Posted November 20, 2007 Share Posted November 20, 2007 HI again, ok i have a code which should update the price of a product depending on how many there are. everything works apart from the update price, last two lines... any idea's? <? include('config.php'); $sql = "SELECT COUNT(`drugs`) FROM `players`"; $result = mysql_query($sql) or die(mysql_error()); $num_drugs = mysql_result($result,0); $sql2 = "SELECT COUNT(`steaks`) FROM `players`"; $result2 = mysql_query($sql2) or die(mysql_error()); $num_steaks = mysql_result($result2,0); mysql_query('UPDATE players SET drugs = drugs + (drugfact*20), dpayout = (drugfact*20), steaks = steaks + (steakhouse*22), spayout = (steakhouse*22);'); mysql_query('UPDATE players SET credits = credits - (employees*wages)'); mysql_query('UPDATE price SET drugs = 10000 / (.$num_steaks)'); mysql_query('UPDATE price SET steaks = 20000 / (.$num_steaks)'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/ Share on other sites More sharing options...
Karl33to Posted November 20, 2007 Share Posted November 20, 2007 it could be that the COUNT() is returning Zero and then MySql is trying to divide 10000 by 0 ? Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395314 Share on other sites More sharing options...
grlayouts Posted November 20, 2007 Author Share Posted November 20, 2007 no the count comes back with a number Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395318 Share on other sites More sharing options...
kenrbnsn Posted November 20, 2007 Share Posted November 20, 2007 What is the "." supposed to be doing in these two statement? <?php mysql_query('UPDATE price SET drugs = 10000 / (.$num_steaks)'); mysql_query('UPDATE price SET steaks = 20000 / (.$num_steaks)'); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395320 Share on other sites More sharing options...
grlayouts Posted November 20, 2007 Author Share Posted November 20, 2007 it was for the echo i had. either way with or without the . is still doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395321 Share on other sites More sharing options...
Wes1890 Posted November 20, 2007 Share Posted November 20, 2007 Maybe try this: <?php mysql_query("UPDATE price SET drugs = 10000 / ($num_steaks)"); mysql_query("UPDATE price SET steaks = 20000 / (.$num_steaks)"); ?> Changing 'single quotes' to "double quotes".. ive heard that you cant use $open_vars in 'single quotes' Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395323 Share on other sites More sharing options...
grlayouts Posted November 20, 2007 Author Share Posted November 20, 2007 nope. still the same. Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395326 Share on other sites More sharing options...
roopurt18 Posted November 20, 2007 Share Posted November 20, 2007 it was for the echo i had. either way with or without the . is still doesn't work Well you are no longer echo'ing anything, so why is the dot still in your query? Usually when you try and fix a problem, this applies to all problem-solving and not just programming, the more information you have about the problem the easier it is to solve. Until you get it resolved, change your code to give you more information: $sql = 'UPDATE price SET drugs = 10000 / (.$num_steaks)'; mysql_query($sql) or die($sql . ' : ' . mysql_error()); $sql = 'UPDATE price SET steaks = 20000 / (.$num_steaks)'; mysql_query($sql) or die($sql . ' : ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395333 Share on other sites More sharing options...
revraz Posted November 20, 2007 Share Posted November 20, 2007 MySQL and PHP treat quotes differently. Maybe try this: <?php mysql_query("UPDATE price SET drugs = 10000 / ($num_steaks)"); mysql_query("UPDATE price SET steaks = 20000 / (.$num_steaks)"); ?> Changing 'single quotes' to "double quotes".. ive heard that you cant use $open_vars in 'single quotes' Quote Link to comment https://forums.phpfreaks.com/topic/78115-query-error/#findComment-395426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.