Problem adding 1 to a mysql collumn

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roondog
Forum Newbie
Posts: 18
Joined: Sun Jul 22, 2007 11:56 am

Problem adding 1 to a mysql collumn

Post by roondog »

using this code

Code: Select all

<?php

$con = mysql_connect ('localhost', '*****', '******');

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("roondog_news", $con);

if (isset($_POST['hometeam1_score'])) {
mysql_query("UPDATE league SET played = played +1
WHERE teamname = {$_POST['hometeam1']} AND
SET played = played +1
WHERE teamname = {$_POST['hometeam2']}");

echo 'points added';
}else{

echo 'something is wrong';

}

mysql_close($con);

?>
i've put the echoes in just to see if its doing anything. it says points added but nothing is added to the database.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

You have an invalid query..

Code: Select all

// Snip
mysql_query("UPDATE league SET played = played +1
WHERE teamname = {$_POST['hometeam1']} AND
SET played = played +1
WHERE teamname = {$_POST['hometeam2']}")
or die('Mysql Query Error: <br>' . mysql_error()); 
User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Post by olog-hai »

it seems that you have error in your sql statement.

why two where clause ?

Code: Select all

WHERE teamname = {$_POST['hometeam1']} OR 
teamname = {$_POST['hometeam2']}");
maybe ?
Post Reply