Strange Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpedit
Forum Newbie
Posts: 2
Joined: Fri Apr 07, 2006 4:38 pm

Strange Problem

Post by phpedit »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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 [url=http://www.intranetjournal.com/articles/200407/ij_07_06_04a.html]this[/url]  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:

Code: Select all

<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">&nbsp;</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">&nbsp;</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>&nbsp;Title:
          <input name="title" type="text" id="title">
        </p>
        <p>&nbsp;Controls:
          <input name="controls" type="text" id="controls">
        </p>
        <p>&nbsp;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>&nbsp;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>
Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your query has an unclosed grouping "VALUES" has a missing paren.

echo out $insetQuery to see it.
phpedit
Forum Newbie
Posts: 2
Joined: Fri Apr 07, 2006 4:38 pm

Post by phpedit »

could you please expand on that, I'm still new to php.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

simple explaination: echo the variable like I said. Count the opening and closing parens. Do they match up?
Post Reply