Hey guys! First post here so I'll make it quick.
The Story:
Well I have been recently designing my own website, and part of that website will feature a page where the user can play flash games. So I decided to store the information (like the title, controls etc.) into a mySql database. The name of this database is 2fun4me, and inside I have two tables: cmsgames (which will store the information of the games) and cmstypes (which will hold the different types of games available). I referred to this tutorial for help.
Now for one of the pages, newGame.php (which is an editor for adding games) I have a form with three text inputs (title, controls and filename) and one dropdown list (the type of game, this is loaded from the mySql database table cmstypes). When I click submit, it gives me a custom error I coded incase something went wrong: "Sorry, there was an error saving to the database." But I cannot find anything wrong with the code. I have several classes like the database connector, a text validator and the main class which the other classes extend, systemComponent. Sorry its a lot of code to wade through, though most of its html. Any ideas on whats wrong?
newGame.php Code:
<html>
<head>
<title>Games section (2fun4me) - The Ultimate Games Experience</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="Keywords here">
<meta name="description" content="Description here">
<meta name="robots" content="index, follow">
<STYLE>A:link {
COLOR: #FFFFFF; TEXT-DECORATION: none
}
A:visited {
COLOR: #FFFFFF; TEXT-DECORATION: none
}
A:hover {
COLOR: #FFFFFF; TEXT-DECORATION: underline
}
</STYLE>
</head>
<body style="margin:0;" background="../images/pixi_darkgrey.gif" link="#FFFFFF" vlink="#FFFFFF" text="#FFFFFF">
<table width="765" border="0" cellspacing="0" cellpadding="0" height="16">
<tr>
<td width="763" height="60" background="../images/toppic2.gif">
<p align="center"><font size="3" face="Verdana"><b>Games section (2fun4me) - The Ultimate Games Experience</b></font></p>
</td>
</tr>
<tr>
<td background="../images/topnavbg.gif" width="763" height="5">
<p align="right"> </p>
</td>
</tr>
<tr>
<td background="../images/navbasebg.gif" width="763" height="4"><font face="Verdana"><img src="../images/navbasebg.gif" width="1" height="2"></font></td>
</tr>
<tr>
<td width="763" height="20">
<p align="right"><b><font size="2" face="Verdana"><a href="../index.php">Home</a> |
<a href="#"> Partners</a> | <a href="#"> Portfolio</a> | <a href="#">
About Us</a> | <a href="#"> Contact Us</a></font></b></p>
</td>
</tr>
<tr>
<td background="../images/navbasebg.gif" width="763" height="4"><font face="Verdana"><img src="../images/navbasebg.gif" width="1" height="2"></font></td>
</tr>
</table>
<table width="765" border="0" cellspacing="0" cellpadding="0" height="16">
<tr>
<td valign="top" width="95" height="20">
<div align="center">
<center>
<table border="0" width="133%" cellspacing="5">
<tr>
<td valign="top" width="90%"><font size="2" face="Verdana" color="#C0C0C0"><b>Menu</b></font>
<p align="left"><font size="2" face="Verdana"><a href="#">Menu Link
1</a></font></p>
<p align="left"><font size="2" face="Verdana"><a href="#">Menu
Link 2</a></font></p>
<p align="left"><font size="2" face="Verdana"><a href="#">Menu Link
3</a></font></p>
<p align="left"><font size="2" face="Verdana"><a href="#">Menu Link
4</a></font></p>
<p align="left"><font size="2" face="Verdana"><a href="#">Menu Link
5</a></font></p>
<p><font size="2" face="Verdana" color="#C0C0C0"><b>Free
Stuff</b></font>
<p><a class="links" href="http://www.best-wallpapers.com"><font face="Verdana" size="2">Wallpapers</font></a>
<p><a class="links" href="http://www.best-wallpapers.com/screensavers.htm"><font face="Verdana" size="2">Screensavers</font></a>
<p><a class="links" href="http://www.best-wallpapers.com/web-template/"><font face="Verdana" size="2">Templates</font></a>
<p><a class="links" href="http://www.best-wallpapers.com/msn/"><font face="Verdana" size="2">Emoticons</font></a>
<p><a class="links" href="http://www.best-wallpapers.com/clip-art/"><font face="Verdana" size="2">Clip
Arts</font></a>
<p><a class="links" href="http://www.best-wallpapers.com/background/"><font face="Verdana" size="2">Backgrounds</font></a>
<p><a class="links" href="http://www.best-wallpapers.com/download-games/"><font face="Verdana" size="2">Games</font></a></td>
<td width="41%" background="../images/pic1cellbg.gif"> </td>
</tr>
</table>
</center>
</div>
</td>
<td width="623" height="20" valign="top">
<div align="center">
<center>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999">
<tr>
<br><br>
<form name="New Game" method="post" action="newGame.php">
<p> Title:
<input name="title" type="text" id="title">
</p>
<p> Controls:
<input name="controls" type="text" id="controls">
</p>
<p> Type:
<select name="type" id="type">
<?PHP
require_once('../includes/DbConnector.php');
// Create an instance of DbConnector
$connector = new DbConnector();
// Generate a drop-down list of sections.
// NOTE : Requires database modifications in article 4
$result = $connector->query('SELECT ID,name FROM cmstypes ORDER BY name');
// Get an array containing the results.
// Loop for each item in that array
while ($row = $connector->fetchArray($result)){
echo '<option value="'.$row['ID'].'">'.$row['name'].'</option>';
}
?>
</select>
</p>
<p> Filename:
<input name="filename" type="text" id="filename">
</p>
<p align="center">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</td>
</tr>
</table>
</center>
</div>
</td>
</tr>
<tr>
<td background="../images/navbasebg.gif" width="763" height="4" colspan="2"><font face="Verdana"><img src="../images/navbasebg.gif" width="1" height="2"></font></td>
</tr>
</table>
</body>
</html>
<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');
require_once('../includes/Validator.php');
// Create an instance of DbConnector
$connector = new DbConnector();
// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){
// Validate the entries
$validator = new Validator();
$validator->validateTextOnly($HTTP_POST_VARS['title'],'Game Title');
$validator->validateTextOnly($HTTP_POST_VARS['controls'],'Game Controls');
$validator->validateNumber($HTTP_POST_VARS['type'],'Game Type');
$validator->validateGeneral($HTTP_POST_VARS['filename'],'Game Filename');
// Check whether the validator found any problems
if ( $validator->foundErrors() ){
echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each
}else{
// Create an SQL query (MySQL version)
$insertQuery = "INSERT INTO cmsgames (title, controls, type, filename) VALUES (".
"'".$HTTP_POST_VARS['title']."', ".
"'".$HTTP_POST_VARS['controls']."', ".
//$HTTP_POST_VARS['type'].", ".
"'1', ".
"'".$HTTP_POST_VARS['filename']."'";
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<center><b>Game added to the database</b></center><br>';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database.'.$validator->listErrors.'</center>');
}
}
}
?>
</body>
</html>