Iryk Posted April 15, 2006 Share Posted April 15, 2006 [code]<? include("db_connect.php"); if($change == "yes") { $col = $collected++; mysql_query("UPDATE `$map` SET $piece='yes' WHERE User='$user'"); mysql_query("UPDATE `$map` SET Collected='$col' WHERE User='$user'"); echo "You're map pieces for <b>$map</b> have been updated."; }?>[/code]That code doesn't seem to be working... any ideas why?Here is the URL that is suppose to make the code work:[a href=\"http://majestic-neo.com/pet_db/update.php?map=Secret%20Laboratory%20Map&user=Iryk&piece=3&change=yes&collected=3\" target=\"_blank\"]http://majestic-neo.com/pet_db/update.php?...yes&collected=3[/a]Or this URL and click on an image to try it:[a href=\"http://majestic-neo.com/pet_db/maps.php?map_num=1\" target=\"_blank\"]http://majestic-neo.com/pet_db/maps.php?map_num=1[/a] Quote Link to comment https://forums.phpfreaks.com/topic/7456-updating-mysql-with-php-isnt-working/ Share on other sites More sharing options...
Jewbilee Posted April 15, 2006 Share Posted April 15, 2006 [code]<?include("db_connect.php");if($change == "yes") { $col = $collected++; mysql_query("UPDATE `$map` SET piece='yes' WHERE User='$user'"); mysql_query("UPDATE `$map` SET Collected='$col' WHERE User='$user'"); echo "You're map pieces for <b>$map</b> have been updated.";}?>[/code]you needed to get rid of the $ next to $piece in your original leaving just piece. that should do it. and you could also join those two statements together like this[code] mysql_query("UPDATE `$map` SET piece='yes' and Collected='$col' WHERE User='$user'");[/code]that should work for you. Quote Link to comment https://forums.phpfreaks.com/topic/7456-updating-mysql-with-php-isnt-working/#findComment-27163 Share on other sites More sharing options...
Iryk Posted April 15, 2006 Author Share Posted April 15, 2006 the $piece served the purpose of telling the function to go to a certain number because there are 9 pieces to a map and it told it which one to change... and the code didn't work either with the change you made sorry. Quote Link to comment https://forums.phpfreaks.com/topic/7456-updating-mysql-with-php-isnt-working/#findComment-27164 Share on other sites More sharing options...
kenrbnsn Posted April 15, 2006 Share Posted April 15, 2006 First, what are the field names in your database table?Next, whenever you're trying to debug MySQL queries, it is very helpful to do each query in multiple lines. For example:[code]<?phpinclude("db_connect.php");if($change == "yes") { $col = $collected++; $query = "UPDATE `$map` SET $piece='yes', Collected='$col' WHERE User='$user'"; $rs = mysql_query($q) or die('There was a problem with the update query: ' . $q . '<br>' . mysql_error()); echo "You're map pieces for <b>$map</b> have been updated.";}?>[/code]This way when you have an error in your query, the query and the error are displayed on the screen.Ken Quote Link to comment https://forums.phpfreaks.com/topic/7456-updating-mysql-with-php-isnt-working/#findComment-27168 Share on other sites More sharing options...
Iryk Posted April 15, 2006 Author Share Posted April 15, 2006 the collumns in my table are:UserCollected123456789The numbers hold the yes and no values and the User holds the username and the Collected holds how many pieces of the map you have collected. Quote Link to comment https://forums.phpfreaks.com/topic/7456-updating-mysql-with-php-isnt-working/#findComment-27170 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.