jetpacmidge Posted February 13, 2006 Share Posted February 13, 2006 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][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> <a href='tadburnfc.htm'>Return To Main Page</a></div></font></body></html>[/code][/code][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";?>[/code]TABLE Informationcreate 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 Quote Link to comment Share on other sites More sharing options...
wickning1 Posted February 13, 2006 Share Posted February 13, 2006 "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());' Quote Link to comment Share on other sites More sharing options...
fenway Posted February 13, 2006 Share Posted February 13, 2006 Agreed -- sounds like an open paren that got converted to an HTML entity by accident. Quote Link to comment Share on other sites More sharing options...
jetpacmidge Posted February 14, 2006 Author Share Posted February 14, 2006 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> <a href='tadburnfc.htm'>Return To Main Page</a></div></font></body></html>Thanks,Andy M. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 14, 2006 Share Posted February 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.