Jump to content


Photo

Football Results Updating Database Problem


  • Please log in to reply
4 replies to this topic

#1 jetpacmidge

jetpacmidge
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationHampshire

Posted 13 February 2006 - 12:51 PM

Hi, I am new to using PHP & MYSQL and have developed a website for entering football results on a website and the tables get automatically updated. Everytime I enter the result a message of couldn't execute query appears. Where have I gone wrong ?? Below is the code for the webpages :-

[code]<?php
  /* Program: AddResult.php
   * Desc:    A confirmation screen  
   *          is sent to the user.
   */

  $season = $_POST['season'];
  $newteam = $_POST['newteam'];
  $fixtureDate = $_POST['fixtureDate'];
  $age = $_POST['age'];
  $division = $_POST['division'];
  $homeTeam = $_POST['homeTeam'];
  $homeScore = $_POST['homeScore'];
  $awayTeam = $_POST['awayTeam'];
  $awayScore = $_POST['awayScore'];
  $matchtype = $_POST['matchtype'];
  $team = $_POST['team'];
  $played = $_POST['played'];
  $won = $_POST['won'];
  $lost = $_POST['lost'];
  $drawn = $_POST['drawn'];
  $goalsfor = $_POST['goalsfor'];
  $goalsagainst = $_POST['goalsagainst'];
  $points = $_POST['points'];

if (@$_POST['newbutton'] == "Cancel")
  {
     header("Location: tadburnfc.htm");
  }
    if ($newteam == "new")
    {
    if ($newhometeam == "") // if the text field is blank
      {
       include("NewResultform.inc");
       exit();
    }
        else
        {
           $newteam = $newhometeam;
        }
    }

  
    
?>
<html>
<head><title>Add Result</title></head>
<?php
  include("connection.inc");
  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");

    $query = "INSERT INTO leagueTable (season,fixtureDate,age,division,homeTeam,homeScore,awayTeam,awayScore,matchtype,team,played,won,lost,drawn,goalsfor,goalsagainst,points)
            VALUES ('$season','$fixtureDate','$age','$division','$homeTeam','$homeScore','$awayTeam','$awayScore','$matchtype','','','','','','','','')";
  $result = mysql_query($query)
       or die ("Couldn't execute query.");
$teamID = mysql_insert_id();

echo "The following result has been added to the Tadburn FC database:<br>
        <ul>
         <li>Season: $season
     <li>Fixture Date: $fixtureDate
         <li>Age Group: $age
         <li>Home Team: $homeTeam
     <li>Home Score: $homeScore
     <li>Away Team: $awayTeam
     <li>Away Score: $awayScore
         <li>Match Type: $matchtype
</ul> \n";
?>
<br>
<br>
<br>
<br>
<br>
<br>
<font face="Arial, Helvetica, sans-serif" size="+2" color="#0000FF">
<div align='center'> <a href='results2.php'>Add Another Result ?</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='tadburnfc.htm'>Return To Main Page</a></div>

</font>
</body>
</html>
[/code]


[code]<?php
  /* Program: results.php
   * Desc:    Allows the user to enter football results.
     *    There are drop down menus to choose the
     *    Division, Age Group, & Football Team
     */
?>
<?php
  if (@$_POST['newbutton'] == "Enter Football Results" or @$_POST['newbutton'] == "Cancel")
  {
    header("Location: tadburnfc.htm");
  }
?>
 <html>
<head><title>Add Football Result</title></head>
<body>
<?php
  include("connection.inc");


  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");


    /* create form */
  echo "<div style='margin-left: .1in'>";
  echo "<form action='AddFootballResult.php' method='post'>\n";

    include("FootballResultInfo_table.inc");

  echo "<input type='hidden' name='category' value='$category'>\n";
  echo "<p><input type='submit' value='Submit Result'>
        <input type='submit' name='newbutton' value='Cancel'>
        </form>\n";
?>

TABLE Information

create table leagueTable (
teamID INT(5) NOT NULL AUTO_INCREMENT,
season CHAR(10) NOT NULL,
fixtureDate VARCHAR(20) NOT NULL,
age CHAR(15) NOT NULL,
division VARCHAR (20) NOT NULL,
homeTeam CHAR(30) NOT NULL,
homeScore INT(3) UNSIGNED NOT NULL,
awayTeam CHAR(30) NOT NULL,
awayScore INT(3) UNSIGNED NOT NULL,
matchtype VARCHAR(10),
team CHAR(30) NOT NULL,
played INT(4) UNSIGNED NOT NULL,
won INT(4) UNSIGNED NOT NULL,
lost INT(4) UNSIGNED NOT NULL,
drawn INT(4) NOT NULL,
goalsfor VARCHAR(4) NOT NULL,
goalsagainst VARCHAR(4) NOT NULL,
points INT(3) NOT NULL,
PRIMARY KEY(teamID) );

Thanks for your help !!

Rgds,

Andy M. :D


#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 13 February 2006 - 03:53 PM

"INSERT INTO leagueTable & #40;season,..."

What's with the & #40;? SQL isn't going to translate HTML codes.

You can get more information about the error by changing 'or die ("Couldn't execute query.");' to 'or die (mysql_error());'

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 February 2006 - 05:17 PM

Agreed -- sounds like an open paren that got converted to an HTML entity by accident.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 jetpacmidge

jetpacmidge
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationHampshire

Posted 14 February 2006 - 06:27 PM

Hi,

Sorry the code should have read :-

<?php
/* Program: AddResult.php
* Desc: A confirmation screen
* is sent to the user.
*/

$season = $_POST['season'];
$newteam = $_POST['newteam'];
$fixtureDate = $_POST['fixtureDate'];
$age = $_POST['age'];
$division = $_POST['division'];
$homeTeam = $_POST['homeTeam'];
$homeScore = $_POST['homeScore'];
$awayTeam = $_POST['awayTeam'];
$awayScore = $_POST['awayScore'];
$matchtype = $_POST['matchtype'];
$team = $_POST['team'];
$played = $_POST['played'];
$won = $_POST['won'];
$lost = $_POST['lost'];
$drawn = $_POST['drawn'];
$goalsfor = $_POST['goalsfor'];
$goalsagainst = $_POST['goalsagainst'];
$points = $_POST['points'];

if (@$_POST['newbutton'] == "Cancel")
{
header("Location: tadburnfc.htm");
}
if ($newteam == "new")
{
if ($newhometeam == "") // if the text field is blank
{
include("NewResultform.inc");
exit();
}
else
{
$newteam = $newhometeam;
}
}



?>
<html>
<head><title>Add Result</title></head>
<?php
include("connection.inc");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");

$query = "INSERT INTO leagueTable (season,fixtureDate,age,division,homeTeam,homeScore,awayTeam,awayScore,matchtype,team,played,won,lost,drawn,goalsfor,goalsagainst,points)
VALUES ('$season','$fixtureDate','$age','$division','$homeTeam','$homeScore','$awayTeam','$awayScore','$matchtype','','','','','','','','')";
$result = mysql_query($query)
or die ("Couldn't execute query.");
$teamID = mysql_insert_id();

echo "The following result has been added to the Tadburn FC database:<br>
<ul>
<li>Season: $season
<li>Fixture Date: $fixtureDate
<li>Age Group: $age
<li>Home Team: $homeTeam
<li>Home Score: $homeScore
<li>Away Team: $awayTeam
<li>Away Score: $awayScore
<li>Match Type: $matchtype
</ul> \n";
?>
<br>
<br>
<br>
<br>
<br>
<br>
<font face="Arial, Helvetica, sans-serif" size="+2" color="#0000FF">
<div align='center'> <a href='results2.php'>Add Another Result ?</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='tadburnfc.htm'>Return To Main Page</a></div>

</font>
</body>
</html>

Thanks,

Andy M.

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 February 2006 - 08:49 PM

Ok, we're not getting anywhere just staring at your scripts -- find the offending query by adding a mysql_error() in your die() statements, and post JUST the query and the erorr.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users