By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Any Ideas why the 2nd and 3rd Query do not work?

P: n/a
<?

// scoreinput.php - input a match score when match selected from list
?>
<html>
<head>
<basefont face="Verdana">
</head>

<body>

<!-- standard page header begins -->
<p>&nbsp;<p>

<table width="100%" cellspacing="0" cellpadding="5">
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="Red"><font size="-1" color="White"><b>Cornwall County
Short Mat Bowling Association : Administration :

League Results : Edit</b></font></td>
</tr>
</table>
<!-- standard page header ends -->

<p>

<?
// includes
include("../conf.php");
include("../functions.php");

// form not yet submitted
// display initial form with values pre-filled
if (!$submit)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// generate and execute query
$query = "SELECT * FROM matches WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

// if a result is returned
if (mysql_num_rows($result) > 0)
{
// turn it into an object
$row = mysql_fetch_object($result);

// print form with values pre-filled
?>
<table cellspacing="5" cellpadding="5">
<form action="<? echo $PHP_SELF; ?>" method="POST">
<input type="hidden" name="id" value="<? echo $row->id; ?>">
<tr>
<td valign="top"><b>Date<b></td>
<td><? echo $row->date; ?></td>
</tr>
<tr>
<td valign="top"><b><? echo $row->home_team; ?></b></td>
<td><input size="5" name="home_shots" value="<? echo
$row->home_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b><? echo $row->away_team; ?></b></td>
<td><input size="5" name="away_shots" value="<? echo
$row->away_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b>Match Completed</b></td>
<td><input type="checkbox" name="completed" value="Y"></td>
</tr>
<tr>
<td colspan=2><input type="Submit" name="submit" value="Update"></td>
</tr>
</form>
</table>
<?
}
// no result returned
// print graceful error message
else
{
echo "<font size=-1>That match could not be located in our
database.</font>";
}
}
// form submitted
// start processing it
else
{
// set up error list array
$errorList = array();
$count = 0;

// check for errors
// if none found...
if (sizeof($errorList) == 0)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// generate and execute query
if ($home_shots > $away_shots) {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryhome = "UPDATE teams
SET played = played + 1,
won = won + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots',
points = points + 2 WHERE team = '$home_team'";
$queryaway = "UPDATE teams
SET played = played + 1,
lost = lost + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots' WHERE team = '$away_team'";
} elseif ($home_shots < $away_shots) {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryaway = "UPDATE teams
SET played = played + 1,
won = won + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots',
points = points + 2 WHERE team = '$away_team'";
$queryhome = "UPDATE teams
SET played = played + 1,
lost = lost + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots' WHERE team = '$home_team'";
} else {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryhome = "UPDATE teams
SET played = played + 1,
drawn = drawn + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots',
points = points + 1 WHERE team = '$home_team'";
$queryaway = "UPDATE teams
SET played = played + 1,
drawn = drawn + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots',
points = points + 1 WHERE team = '$away_team'";
}
$result1 = mysql_query($querymatches) or die ("Error in query:
$query. " . mysql_error());
$result2 = mysql_query($queryhome) or die ("Error in query: $query.
" . mysql_error());
$result3 = mysql_query($queryaway) or die ("Error in query: $query.
" . mysql_error());

// print result
echo "<font size=-1>Update successful. <a href=list.php>Go back to
the main menu</a>.</font>";

// close database connection
mysql_close($connection);
}
else
{
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
?>

<!-- standard page footer begins -->
<p>
<table width="100%" cellspacing="0" cellpadding="5">
<tr>
<td align="center">&nbsp;</td>
</tr>
</table>
<!-- standard page footer ends -->
</body>
</html>
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Nick Truscott wrote:
// scoreinput.php - input a match score when match selected from list


Echo your queries to screen and copy-paste them to mysql client. Then
copy-paste the queries, error messages from MySQL and table structure
for tables that are used in queries, here and it will make it a lot
easier for us to help you. Also tell what version of MySQL you are
using. We might see the errors directly from the queries, so it might be
enough if you copy-paste those here. But it is easier if you show it all
at once.
Jul 20 '05 #2

P: n/a
Here is the table structure, I do not get an error message, just the
2nd and 3rd queries do not run.

CREATE TABLE `matches` (
`id` int(11) NOT NULL auto_increment,
`date` date NOT NULL default '0000-00-00',
`time` time NOT NULL default '00:00:00',
`home_team` text NOT NULL,
`away_team` text NOT NULL,
`home_shots` int(11) NOT NULL default '0',
`away_shots` int(11) NOT NULL default '0',
`league` text NOT NULL,
`completed` text,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

CREATE TABLE `teams` (
`id` int(11) NOT NULL auto_increment,
`league` text NOT NULL,
`team` text NOT NULL,
`played` int(11) NOT NULL default '0',
`won` int(11) NOT NULL default '0',
`drawn` int(11) NOT NULL default '0',
`lost` int(11) NOT NULL default '0',
`sf` int(11) NOT NULL default '0',
`sa` int(11) NOT NULL default '0',
`bonus` int(11) NOT NULL default '0',
`points` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
Aggro <sp**********@yahoo.com> wrote in message news:<SY*************@read3.inet.fi>...
Nick Truscott wrote:
// scoreinput.php - input a match score when match selected from list


Echo your queries to screen and copy-paste them to mysql client. Then
copy-paste the queries, error messages from MySQL and table structure
for tables that are used in queries, here and it will make it a lot
easier for us to help you. Also tell what version of MySQL you are
using. We might see the errors directly from the queries, so it might be
enough if you copy-paste those here. But it is easier if you show it all
at once.

Jul 20 '05 #3

P: n/a
Nick Truscott wrote:
Here is the table structure, I do not get an error message, just the
2nd and 3rd queries do not run.


What do you mean they don't run? Don't they do the result you are
expecting or are they not called and executed at all?

If the query returns 0 rows, could you echo it on the screen and
copy-paste here? You have only shown us the php code which is used to
generate the queries. It is very very very common that programmer makes
a mistake while generating the query, for example some value is
incorrect. That's why it is important that you echo the real query you
are trying to use to see what the query really looks like. It is also a
lot easier to see from there what the problem might be.

If they are not called at all, it is a problem with your php code and
questions about php should be asked in a different group, like
comp.lang.php for example.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.