Jump to content


Photo

Finally have it working - update MYSQL Query


  • Please log in to reply
1 reply to this topic

#1 tstats

tstats
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 March 2006 - 02:59 AM

Thanks for all of your help on this subject -

I have two pieces of code - the first set of code is here:


<html><head><title></title></head>
<body>
<?
$ud_id=$_POST['ud_id'];
$ud_score1=$_POST['ud_score1'];
$ud_score2=$_POST['ud_score2'];
$ud_diff=$_POST['ud_diff'];

//connect to db with password above this line
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());

mysql_query(" UPDATE acsb061 SET score1='$ud_score1',score2='$ud_score2', diff='$ud_diff' WHERE id='$ud_id'");
mysql_close($link);
require 'updatenext.php';
?>
</body>
</html> 


The second set of code is here - which updates the database -


<html><head><title></title></head>
<body>
<?
$ud_id=$_POST['ud_id'];
$ud_score1=$_POST['ud_score1'];
$ud_score2=$_POST['ud_score2'];
$ud_diff=$_POST['ud_diff'];
$db = "tourname_Tour"; 
$link = mysql_connect("localhost","tourname","tmrcdrdlr");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());

mysql_query(" UPDATE acsb061 SET team1='$ud_team1' ,team2='$ud_team2',score1='$ud_score1',score2='$ud_score2', diff='$ud_diff' WHERE id='$ud_id'");
mysql_close($link);
require 'updatefirst.php';
?>
</body>
</html> 


Ok - so here is my question. Right now, I am having to enter the $diff in the html form - how would I write it so that the $diff in code set 1 above would be calculated?

I would just enter the two scores and the $diff field (which is score1 - score2) would automatically be calculated and then passed through to the updatenext.php file -

Thanks for the help -

#2 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 05 March 2006 - 07:05 AM

This should work fine in place of $ud_diff=$_POST['ud_diff'];

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$ud_diff= $ud_score1 - $ud_score2;[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users