Jump to content

Updating MYSQL with php isn't working


Iryk

Recommended Posts

[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]
Link to comment
https://forums.phpfreaks.com/topic/7456-updating-mysql-with-php-isnt-working/
Share on other sites

[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.
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]<?php
include("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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.