Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $self = $_SERVER['PHP_SELF'];
- function insertRecord($pName, $pSpecies, $pBreed, $pPrice, $pImage){
- $insertQuery = "INSERT into tblPets (petName, petSpecies, petBreed, petPrice, petImage)
- VALUES ('$pName', '$pSpecies', '$pBreed', '$pPrice', '$pImage')";
- $result = mysql_query($insertQuery);
- }
- //--------Connecting to MYSQL -----------------
- $host = "kate.ict.op.ac.nz";
- $user = "randaaj1";
- $password = "randaaj1";
- $connection = mysql_connect($host, $user, $password)
- or die ("Couldn't select database");
- //echo ("<p>Connecting to MYSQL...</p>");
- //----------Database Connection------------------
- $database = "randaaj1_in612";
- $db = mysql_select_db($database, $connection)
- or die ("Could'nt select database");
- //echo ("<p>Connecting to Database...</p>");
- //-----------Drop The Table-----------------------
- $dropTable = "DROP TABLE tblPets";
- $result = mysql_query($dropTable);
- //echo ("<p>Clean Out Old Table(s)</p>");
- //-----------Create Table-----------------------
- $createTable = "CREATE TABLE tblPets
- (
- petID INT(6) NOT NULL AUTO_INCREMENT,
- petName VARCHAR(20) NOT NULL,
- petSpecies VARCHAR(20) NOT NULL,
- petBreed VARCHAR(20) NOT NULL,
- petPrice DECIMAL(7,2)NOT NULL,
- petImage VARCHAR(20) NOT NULL,
- PRIMARY KEY(petID)
- )";
- $result = mysql_query($createTable);
- //echo ("<p>Creating Pet Table...</p>");
- //-----------Table Structure---------------------
- $selectString = "SHOW COLUMNS FROM tblPets";
- $result = mysql_query($selectString);
- //echo ("<p>Table Structure...</p>");
- //-----------Display Table---------------------
- echo ("<table border = '0' cellpadding ='0'>");
- while ($row = mysql_fetch_row($result)){
- echo ("<tr>");
- foreach($row as $value)
- echo("<td>$value</td>");
- echo("</tr>");
- }
- echo ("</table>");
- //-----------Inserting Table Records-----------------------------------
- insertRecord('Buttons', 'Bird', 'Budgie', '40.00', 'buttons.jpg');
- insertRecord('Bob', 'Guinea Pig', 'English Cavy', '10.00', 'bob.jpg');
- insertRecord('Elmer', 'Guinea Pig', 'English Cavy', '10.00', 'elmer.jpg');
- insertRecord('Fido', 'Dog', 'Poodle', '300.00', 'fido.jpg');
- insertRecord('Flame', 'Guinea Pig', 'English Cavy', '10.00', 'flame.jpg');
- insertRecord('Fluffy', 'Cat', 'Siamese', '100.00', 'fluffy.jpg');
- insertRecord('Glug', 'Fish', 'Gold Fish', '20.00', 'glug.jpg');
- insertRecord('Lachien', 'Dog', 'Poodle', '300.00', 'lachien.jpg');
- insertRecord('Mewmew', 'Cat', 'Siamese', '100.00', 'mewmew.jpg');
- insertRecord('Mouser', 'Cat', 'Siamese', '100.00', 'mouser.jpg');
- insertRecord('Othello', 'Fish', 'Gold Fish', '20.00', 'othello.jpg');
- insertRecord('Polly', 'Bird', 'Budgie', '40.00', 'polly.jpg');
- insertRecord('Snoopy', 'Dog', 'Jack Russell', '200.00', 'snoopy.jpg');
- insertRecord('Trigger', 'Horse', 'Przewalski', '5000.00', 'trigger.jpg');
- insertRecord('Zippy', 'Horse', 'Przewalski', '5000.00', 'zippy.jpg');
- insertRecord('Harry', 'Horse', 'Przewalski', '8000.00', 'harry.jpg');
- Function search(){
- echo("<form action = '$self' method='POST'>");
- echo("<tr><th>
- <fieldset>
- Species:
- <input type='text' name='textSearch' size='30'>
- <input type='submit' name='seachNow' value='Search Now'>
- </fieldset></th></tr>");
- echo("</form>");
- }
- Function display(){
- echo("<form action = '$self' method='POST'>");
- $text = $_POST['textSearch'];
- //-----------Select All Records--------------
- $selectString = "SELECT * FROM tblPets";
- $result = mysql_query($selectString);
- echo "<br>";
- //-----------Display Table---------------------
- //
- echo ("<table border = '2' cellpadding ='10'>");
- echo("<tr><th>ID</th><th>Name</th><th>Species</th><th>Breed</th><th>Price</th><th>Image-Name</th><th>Image</th></tr>");
- while ($row = mysql_fetch_row($result)){
- echo ("<tr>");
- foreach($row as $value){
- echo("<td>$value</td>");
- }
- echo "<td><img src = images/$value></td>"; //Displays the last value (image) in a new field
- echo("</tr>");
- }
- echo ("</table>");
- echo("</form>");
- }
- if (isset($_POST['searchNow'])){
- display();
- }else{
- search();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement