Page 1 of 1

Problem adding 1 to a mysql collumn

Posted: Thu Sep 06, 2007 8:51 am
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.

Posted: Thu Sep 06, 2007 8:57 am
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()); 

Posted: Thu Sep 06, 2007 9:05 am
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 ?