473,769 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP MySQL Queries

Is this possible?

I have a form which asks the user to input the result of a soccer
match.

I want to then use a choice of three sets of queries (Home Win, Away
Win, Draw) to update two tables, Matches (the master list of all
matches and there results) and Teams (a list of all teams with total
numbers of matches played, won, lost drawn etc?)

So far I have managed to update the table matches but nothing happens
to teams. The page appears to run correctly so I am at a loss to
understand what is happening.

PHP AS IT STANDS

<?

// 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($qu ery) 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_obj ect($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_shot s" value="<? echo
$row->home_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b ><? echo $row->away_team; ?></b></td>
<td><input size="5" name="away_shot s" 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><inpu t 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($errorL ist) == 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($qu erymatches) or die ("Error in query:
$query. " . mysql_error());
$result2 = mysql_query($qu eryhome) or die ("Error in query: $query.
" . mysql_error());
$result3 = mysql_query($qu eryaway) or die ("Error in query: $query.
" . mysql_error());

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

// close database connection
mysql_close($co nnection);
}
else
{
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($erro rList); $x++)
{
echo "<li>$error List[$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>

TABLE STRUCTURE
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;
Jul 17 '05 #1
0 1398

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3527
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
0
2691
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ===================================
0
519
by: Plymouth Acclaim | last post by:
Hi guys, We have a problem with Dual AMD64 Opteron/MySQL 4.0.18/Mandrake 10 for a very high volume site. We are evaluating the performance on our new server AMD64 and it seems it's slow compared to Dual Xeon/MySQL 4.0.15/RedHat8 and Dual Xeon/MySQL 4.0.18/Mandrake 10. And it seems there are zombie threads. 570 threads in 1 hour and we didn't even use JDBC connection pooling at all. These threads are supposed to be gone within 60...
11
17572
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time to load making any kind linkage with my Access data virtually useless. I have the MySQL driver setup in as a USER DSN. The MySQL data is sitting out on a server and the Access database is running locally. The network connection is very...
39
8428
by: Mairhtin O'Feannag | last post by:
Hello, I have a client (customer) who asked the question : "Why would I buy and use UDB, when MySql is free?" I had to say I was stunned. I have no experience with MySql, so I was left sort of stammering and sputtering, and managed to pull out something I heard a couple of years back - that there was no real transaction safety in MySql. In flight transactions could be lost.
7
2734
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both of the queries work fine when I use them to query the MySQL server directly. My guess is that the MySQL extension only expects a single resource back from the database, but get's several, or that it just checks the statement first, and decides...
1
5285
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to #./configure it goes through all of the preparing tables and starting mysqlServer and daemon, but than immediaetly says "mysql ended" -- I try to do #make right after anyway, but I get the error "No targets specified and no makefile found" -- Any...
4
4898
by: Federico | last post by:
Hi everybody, I'm evaluating the possibility of using MySQL 5.0 as a database backend for an application we are doing and I'd like to have hardware requirements rough estimates and/or real world experience from people that are already running similar dimensioned database/application. As a rought estimate the database has around 80 tables 4-5 of these are supposed to grow up to 5.000.000 records another 30% will be in the 100.000 range...
13
3424
by: Ciaran | last post by:
Hi All, Is it faster to have mySql look up as much data as possible in one complex query or to have php do all the complex processing and submit lots of simple queries to the mysql database? Cheers, Ciarán
6
38519
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.