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
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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.