06-03-2005, 12:59 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: May 2005
Location: Maine|USA
Posts: 17
Thanks: 0
|
Multiple If satements
I have a php file that has an if statement... If this link is clicked, it will show a web form and not show anything else. If the link is not clicked the data will be shown.
Now, I want to have another link that will load only a certain type of data, basically sorting the MySQL information a certain way. I'm not sure how to implement this.
Here's the current code that I have now:
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</td><td width="200">Title</td><td width="110">Developer</td><td width="140">Publisher</td><td width="140">Year</td><td width="140">Purchased</td><td width="88">Genre</td><td width="120">Serial</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>
|
|
|