Advertisement
xReala

Untitled

Oct 9th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.13 KB | None | 0 0
  1. <?php if(isset($_POST['submit'])){
  2.     $name= $_POST['placename'];
  3.     $description=$_POST['description'];
  4.     $type=$_POST['place_type'];
  5.     $add=$_POST['address'];
  6.     $website=$_POST['website'];
  7.     $city=$_POST['city'];
  8.     if(strlen($name)!=0 && strlen($description)!=0 && $type!='choose' && strlen($website)!=0 && strlen($city)!=0){
  9.         $lines=file('/home/bti320_153b17/secret/topsecret.txt');
  10.         $host=trim($lines[0]);
  11.         $user=trim($lines[1]);
  12.         $password=trim($lines[2]);
  13.         $database=trim($lines[3]);
  14.         $connection = mysql_connect($host, $user, $password) or die("Opening connection failed"). mysql_error($connection);
  15.         $selectdv = mysql_select_db($database, $connection) or die("Select db fail");
  16.         /*if(!$connection){
  17.             die("connection failed: ". mysqli_connect_error());
  18.         }*/
  19.         $sql="INSERT INTO place (placeName ,description, address, website, city, type) VALUES ('$name','$description', '$add', '$website', '$city', '$type')";
  20.         $query = mysql_query($sql, $connection) or die("Insert fail").mysql_error($connection);
  21.         //mysqli_close();
  22.         header("Location: http://zenit.senecac.on.ca/~bti320_153b17/lab3/viewPlaces.php");
  23.         exit();
  24.     }
  25. }
  26. ?>
  27. <html>
  28. <head>
  29.     <link rel="stylesheet" type="text/css" href="addPlace.css">
  30. </head>
  31. <body>
  32. <h2>Towards A Place Recommendation System</h2>
  33. <p>Click <a href="http://zenit.senecac.on.ca/~bti320_153b17/lab3/viewPlaces.php">here</a> to go to the table</p>
  34. <form action="addPlace.php" method="post">
  35.     <label>Place Name</label> <input type="text" name="placename" value="<?php fill('placename')?>"><label><?php error('placename')?></label>
  36.     <label>Description</label> <textarea name="description" rows="4" cols="20" placeholder="Enter text here..."><?php fill('description')?></textarea><label><?php error('description')?></label>
  37.     <label>Type </label>
  38.     <select name="place_type" required>
  39.         <option name="choose" value="" disabled selected <?php if (!isset($_POST)) echo "disabled SELECTED"; ?>>--Choose one--</option>
  40.         <option name="park" value="park"<?php if(isset($_POST['place_type']) && $_POST['place_type']=="park"){ echo "selected";}?>>park</option>
  41.         <option name="zoo" value="zoo"<?php if(isset($_POST['place_type']) && $_POST['place_type']=="zoo"){ echo "selected";}?>>zoo</option>
  42.         <option name="airport" value="airport"<?php if(isset($_POST['place_type']) && $_POST['place_type']=="airport"){ echo "selected";}?>>airport</option>
  43.     </select>
  44.     <label>Address</label> <input type="text" name="address" value="<?php fill('address') ?>"><label><?php error('address')?></label>
  45.     <label>Website</label> <input type="text" name="website" value="<?php fill('website')?>"><label><?php error('website') ?></label>
  46.     <label>City</label><input type="text" name="city" value="<?php fill('city')?>"><label><?php error('city')?></label>
  47.    
  48.     <br/>
  49.     <?php if(isset($_POST['submit'])){if($_POST['place_type']=='choose')echo"please select one";}?><br/>
  50.     <input type="submit" value="Add" name="submit"><br>
  51.     <?php
  52.         function error($key){
  53.             if(isset($_POST['submit'])){
  54.                 $length=strlen($_POST[$key]);
  55.                 if($length==0) echo "input at least one character<br\>";
  56.             }
  57.         }
  58.         function fill($key){
  59.            echo isset($_POST[$key]) ? $_POST[$key] : '';
  60.         }
  61.     ?>      
  62. </form>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement