Jump to content


Photo

Updating MYSQL with php isn't working


  • Please log in to reply
4 replies to this topic

#1 Iryk

Iryk
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 15 April 2006 - 04:57 AM

<?
 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.";
 }
?>

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]

#2 Jewbilee

Jewbilee
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 15 April 2006 - 05:05 AM

<?
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.";
}
?>

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

  mysql_query("UPDATE `$map` SET piece='yes' and Collected='$col' WHERE User='$user'");


that should work for you.

#3 Iryk

Iryk
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 15 April 2006 - 05:08 AM

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.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 15 April 2006 - 05:35 AM

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:
<?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.";
}
?>
This way when you have an error in your query, the query and the error are displayed on the screen.

Ken

#5 Iryk

Iryk
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 15 April 2006 - 05:47 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users