Jump to content

Archived

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

Iryk

Updating MYSQL with php isn't working

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]

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
the collumns in my table are:

User
Collected
1
2
3
4
5
6
7
8
9

The 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.

Share this post


Link to post
Share on other sites

×

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.