View Single Post
Old 06-03-2005, 07:04 PM   #5 (permalink)
Ogden2k
The Wanderer
 
Join Date: May 2005
Location: Maine|USA
Posts: 17
Thanks: 0
Ogden2k is on a distinguished road
Default

I'm still confused, I tried a few different layouts and wasn't able to get this to work. Here's what I currently have for code that works, at the top you can see that the
<?php
if (isset($_GET['addgame'])): // User wants to add a Xbox Title
?>
statement is where it only shows the add form, then after the add form HTML, there's an if statement that loads the actual PHP code for the rest of the site.

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Games Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="http://misc.techiehq.net/stuff/css/games.css" />
</head>
<body>
<div class="body_fore">
<?php
if (isset($_GET['addgame'])): // User wants to add a Xbox Title
?>
<div class="title">Submit a game</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>
Please enter the following information:<br /><br />
<table>
<tr>
    <td>System:</td><td><select name="system"><optgroup label="Game Systems:"><option value="Game Cube" name="Cube">Game Cube</option><option value="PC" name="PC">PC</option><option value="Xbox" name="Xbox">Xbox</option></optgroup></select></td>
</tr>
<tr>
    <td>Title:</td><td><input class="forms" type="text" size="50" maxlength="50" name="title" /></td>
</tr>
<tr>
    <td>Developer:</td><td><input class="forms" type="text" size="50" maxlength="50" name="developer" /><td>
</tr>
<tr>
    <td>Publisher:</td><td><input class="forms" type="text" size="50" maxlength="50" name="publisher" /></td>
</tr>
<tr>
    <td>Year:</td><td><input class="forms" value="0000-00-00" type="text" size="50" maxlength="50" name="year" /><td>
</tr>
<tr>
    <td>Purchased:</td><td><input class="forms" value="0000-00-00" type="text" size="50" maxlength="50" name="purchased" /><td>
</tr>
<tr>
    <td>Genre:</td><td><input class="forms" type="text" size="50" maxlength="50" name="genre" /><td>
</tr>
<tr>
    <td>ISBN:</td><td><input class="forms" type="int" size="50" maxlength="50" name="ISBN" /><td>
</tr>
<tr>
    <td>Serial:</td><td><input class="forms" type="int" size="50" maxlength="50" name="serial" /><td>
</tr> 
</table>
</label>
<br /><input type="submit" value="Submit" />
</form>
<?php else: // Home page display
// Connect to the DB server
$dbcnx = @mysql_connect('localhost''''');
if (!
$dbcnx) {
exit(
'<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the binarydr_stuff DB
if (!@mysql_select_db('binarydr_stuff')) {
exit(
'<p>Unable to locate the stuff ' .
'database at this time.</p>');
}
if (isset(
$_POST['title'])) { //Check for a field that is mandatory to do the insert 
 
$system mysql_escape_string($_POST['system']);
$title mysql_escape_string($_POST['title']); 
$publisher mysql_escape_string($_POST['publisher']); 
$year mysql_escape_string($_POST['year']);
$purchased mysql_escape_string($_POST['purchased']);
$developer mysql_escape_string($_POST['developer']);
$genre mysql_escape_string($_POST['genre']);    
$ISBN mysql_escape_string($_POST['ISBN']);
$serial mysql_escape_string($_POST['serial']);
$sql "INSERT INTO games (system, title, publisher, year, purchased, developer, genre, ISBN, serial) 
             VALUES('
$system','$title','$publisher','$year','$purchased','$developer','$genre','$ISBN','$serial')"
mysql_query($SQL); 
if (@
mysql_query($sql)) {
echo 
'<em>Your data has been added</em><br />';
} else {
echo 
'<p>Error adding submitted info: ' mysql_error(). '</p>';
}
}
echo 
'<div class="title">Games:</div>
<table class="table_head">
<tr>
     <td width="85">System ^ v</td>
     <td width="200">Title ^ v</td>
     <td width="110">Developer ^ v</td>
     <td width="140">Publisher ^ v</td>
     <td width="140">Year ^ v</td>
     <td width="140">Purchased ^ v</td>
     <td width="88">Genre ^ v</td>
     <td width="120">Serial ^ v</td>
</tr>
</table>
'
;
// Request the text of all the info
$result = @mysql_query('SELECT * FROM games');
if (!
$result) {
exit(
'<p>Error performing query: ' mysql_error() . '</p>');
}
// Display the text of each game in a row
while ($row mysql_fetch_array($result)) {
echo 
'
<table class="cells">
<tr>
     <td width="85">' 
$row['system'] . '</td>
     <td width="200">' 
$row['title'] . '</td>
     <td width="110">' 
$row['developer'] . '</td>
     <td width="140">' 
$row['publisher'] . '</td>
     <td width="140">' 
$row['year'] . '</td>
     <td width="140">' 
$row['purchased'] . '</td>
     <td width="88">' 
$row['genre'] .'</td>
     <td width="120">' 
$row['serial'] .'</td>
</tr>
</table>
'
;
}
// When clicked, this link will load this page with the hook sub form displayed
echo '<div class="button_area">
<p>[ <a href="' 
$_SERVER['PHP_SELF'] . '?addgame=1">Add a Game</a> | <a href="search.php">Search</a> | <a href="../">Home</a> | <a href="' $_SERVER['PHP_SELF'] . '">Refresh</a> ]</p></div>
</div>
</div>'
;
endif;
?>
</body>
</html>
__________________
TechieHQ
Send a message via AIM to Ogden2k
Ogden2k is offline  
Reply With Quote