06-03-2005, 07:14 PM
|
#6 (permalink)
|
|
The Acquainted
Join Date: May 2005
Posts: 106
Thanks: 0
|
ok, first to make sure
1) if addgame is in the url means show the form
2) when the form is submitted then enter the info in database and show the info
Now you wanna add
3) if, say, search is in the url then search the database. if i am right then heres the code which will work
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
/*
HERE STARTS MY CODE
change $_GET['search'] to whichever value you will use in the url
*/
elseif(isset($_GET['search'])):
<form>
<input type="text" name="search" value="Search Database">
</form>
/*
HERE ENDS MY CODE
*/
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','$p urchased','$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>
hope this helps
__________________
---------------------------
Errors = Improved Programming.
Portfolio
|
|
|