Advertisement
thotfrnk

assignment1.php

Oct 27th, 2023
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.38 KB | None | 0 0
  1. //contact.php
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <title>Welcome!</title>
  8.  
  9.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  10.  
  11.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  12.  
  13. </head>
  14. <body class="box">
  15.   <!--Navigation bar-->
  16.  
  17. <div>
  18.     <nav>
  19.       <ul>
  20.         <li><a href="../index.html">Home</a></li>
  21.         <li><a href="gallery.php">Gallery</a></li>
  22.         <li><a href="../html/upload.html">Create Post</a></li>
  23.         <li><a href="../html/contact.html">Contact Us</a></li>
  24.         <li><a href="../html/reg_form.html">Register</a></li>
  25.         <li><a href="#">Login</a></li>
  26.       </ul>
  27.       <input type="text" placeholder="Search" id="search">
  28.     </nav>
  29.   </div>
  30.  
  31.   <br><br>
  32.  
  33.   <?php
  34.  
  35. $username = $_POST["user_name"];
  36. $email = $_POST["email"];
  37. $feedback = $_POST["feedback"];
  38.  
  39. //store our connection credentials in variables;  
  40. $server = 'localhost';  
  41. $user = 'root';  
  42. $pass = '';
  43. //there is no password for the my current setup of MySQL  
  44. $dbase = 'assignment1';      
  45. //make the actual connection to myaql and the chosen database  
  46. $conn = mysqli_connect($server, $user, $pass, $dbase);  
  47.  //if the connection failed print error message
  48.  if (!$conn) {    
  49.     die('Could not connect to database because: ' . mysqli_connect_error());    
  50.  }  
  51.   /*else echo "You are successfully connected to $dbase <br>";*/
  52.  
  53.   //use PHP variables as input to MqSQL query.
  54. $qry = "INSERT INTO user_feedback (username, email, feedback) VALUES ('$username', '$email', '$feedback');";  
  55. //only quote text data
  56. //use double quotes on the outside and single quotes on the inside
  57.  
  58. //execute the query    
  59. $result = mysqli_query($conn, $qry);
  60.  
  61. //check on the success of the query
  62.  if(!$result) echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';  
  63.  /*echo 'record successfully inserted.<br><br>';*/
  64.   /*else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';*/  
  65.  //close the connection
  66.  mysqli_close($conn);
  67.  
  68.   ?>
  69.  
  70. <p>Thank you for your feedback! We will get back to you soon.</p>
  71.  
  72.   <!--Footer-->
  73.  
  74.  <div class="footer">
  75.     <footer>
  76.       <p>&copy; 2023 PhotoShare</p>
  77.     </footer>
  78.   </div>
  79.  
  80. </body>
  81. </html>
  82.  
  83. //gallery.php
  84. <!DOCTYPE html>
  85. <html lang="en">
  86. <head>
  87.   <meta charset="UTF-8">
  88.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  89.   <title>Gallery</title>
  90.  
  91.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  92.  
  93.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  94.  
  95. </head>
  96. <body class="box">
  97.  
  98. <!--Navigation bar-->
  99.  
  100. <div>
  101.     <nav>
  102.       <ul>
  103.         <li><a href="../index.html">Home</a></li>
  104.         <li><a href="gallery.php">Gallery</a></li>
  105.         <li><a href="../html/upload.html">Create Post</a></li>
  106.         <li><a href="../html/contact.html">Contact Us</a></li>
  107.         <li><a href="../html/reg_form.html">Register</a></li>
  108.         <li><a href="#">Login</a></li>
  109.       </ul>
  110.       <input type="text" placeholder="Search" id="search">
  111.     </nav>
  112.   </div>
  113.  
  114.   <br><br>
  115.  
  116.   <h1 class="header_center">User Posts</h1>
  117.  
  118.   <!--All images used came from pexels.com under the 'landscape' search, the orginal photographers' names are in the names of the images used in this gallery. Retrieved 21st Oct. 2023.-->
  119.  
  120.  <?php
  121.  
  122.  //store our connection credentials in variables;  
  123. $server = 'localhost';  
  124. $user = 'root';  
  125. $pass = '';
  126. //there is no password for the my current setup of MySQL  
  127. $dbase = 'assignment1';      
  128. //make the actual connection to myaql and the chosen database  
  129. $conn = mysqli_connect($server, $user, $pass, $dbase);  
  130.  //if the connection failed print error message
  131.  if (!$conn) {    
  132.     die('Could not connect to database because: ' . mysqli_connect_error());    
  133.  }  
  134.   //else echo "You are successfully connected to $dbase <br>";
  135.  
  136.  
  137.  //Create the query string
  138.  $query = "select * from post_info";
  139.  
  140.  //execute the query
  141.  $result = mysqli_query($conn, $query);
  142.  if ($result) {
  143.  
  144.    if (mysqli_num_rows($result) > 0) {
  145.  
  146.      // if we are in this block it means that $result was NOT false and it contained
  147.      // at least one row of data... so let's process the data one row at a time
  148.  
  149.      while ($row = mysqli_fetch_assoc($result)) {
  150.  
  151.        // if we are in this inner block it means that we just successfully retrieved
  152.  
  153.        // a row of data from the resultset held in $result. We can embed this in
  154.        // our HTML page as shown below
  155.  
  156.        echo "<div class=\"gallery\">
  157.  
  158.       <img src='$row[picture]'  alt='User Upload' width='500' height='333'>
  159.  
  160.       <br>
  161.  
  162.       <div class=\"caption\">$row[caption]</div>
  163.  
  164.       <div class=\"author\"><strong>$row[author]</strong></div>
  165.  
  166.       <div class=\"date\">$row[post_date]</div>
  167.      
  168.       </div>";
  169.  
  170.      }
  171.      //end while loop
  172.  
  173.    }
  174.    //end if 1 or more rows
  175.  
  176.    else
  177.      echo "<br>No rows returned";
  178.  }
  179.  mysqli_close($conn);
  180.  ?>
  181.  
  182.  <!--Footer-->
  183.  
  184.  <div class="footer">
  185.     <footer>
  186.       <p>&copy; 2023 PhotoShare</p>
  187.  
  188.       <p>
  189.     <a href="http://jigsaw.w3.org/css-validator/check/referer">
  190.         <img style="border:0;width:88px;height:31px"
  191.             src="http://jigsaw.w3.org/css-validator/images/vcss"
  192.             alt="Valid CSS!" />
  193.     </a>
  194. </p>
  195.     </footer>
  196.   </div>
  197.  
  198. </body>
  199. </html>
  200.  
  201. //register.php
  202. <!DOCTYPE html>
  203. <html lang="en">
  204. <head>
  205.   <meta charset="UTF-8">
  206.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  207.   <title>Welcome!</title>
  208.  
  209.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  210.  
  211.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  212.  
  213. </head>
  214. <body class="box">
  215.  
  216.   <!--Navigation bar-->
  217.  
  218. <div>
  219.     <nav>
  220.       <ul>
  221.         <li><a href="../index.html">Home</a></li>
  222.         <li><a href="gallery.php">Gallery</a></li>
  223.         <li><a href="../html/upload.html">Create Post</a></li>
  224.         <li><a href="../html/contact.html">Contact Us</a></li>
  225.         <li><a href="../html/reg_form.html">Register</a></li>
  226.         <li><a href="#">Login</a></li>
  227.       </ul>
  228.       <input type="text" placeholder="Search" id="search">
  229.     </nav>
  230.   </div>
  231.  
  232.   <br><br>
  233.  
  234.   <?php
  235.  
  236. $username = $_POST["user_name"];
  237. $email = $_POST["email"];
  238. $pword = $_POST["pword"];
  239. $fname = $_POST["fname"];
  240. $lname = $_POST["lname"];
  241. $age = $_POST["age"];
  242. $phone = $_POST["phone"];
  243.  
  244. echo "<h1>Welcome to PhotoShare $username!</h1>
  245. <br>";
  246.  
  247. //store our connection credentials in variables;  
  248. $server = 'localhost';  
  249. $user = 'root';  
  250. $pass = '';
  251. //there is no password for the my current setup of MySQL  
  252. $dbase = 'assignment1';      
  253. //make the actual connection to myaql and the chosen database  
  254. $conn = mysqli_connect($server, $user, $pass, $dbase);  
  255.  //if the connection failed print error message
  256.  if (!$conn) {    
  257.     die('Could not connect to database because: ' . mysqli_connect_error());    
  258.  }  
  259.   /*else echo "You are successfully connected to $dbase <br>";*/
  260.  
  261.   //use PHP variables as input to MqSQL query.
  262. $qry = "INSERT INTO user_info (username, email, pword, fname, lname, age, phone_num) VALUES ('$username', '$email', '$pword', '$fname', '$lname', '$age', '$phone');";  
  263. //only quote text data
  264. //use double quotes on the outside and single quotes on the inside
  265.  
  266. //execute the query    
  267. $result = mysqli_query($conn, $qry);
  268.  
  269. //check on the success of the query
  270.  if(!$result) echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';  
  271.  /*echo 'record successfully inserted.<br><br>';*/
  272.   /*else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';*/  
  273.  //close the connection
  274.  mysqli_close($conn);
  275.  
  276.   ?>
  277.  
  278. <p>You can create a post <a href='../html/upload.html'>here</a> or check out other users posts in the <a href='gallery.php'>Gallery</a>.</p>
  279.  
  280.   <!--Footer-->
  281.  
  282.  <div class="footer">
  283.     <footer>
  284.       <p>&copy; 2023 PhotoShare</p>
  285.  
  286.       <p>
  287.     <a href="http://jigsaw.w3.org/css-validator/check/referer">
  288.         <img style="border:0;width:88px;height:31px"
  289.             src="http://jigsaw.w3.org/css-validator/images/vcss"
  290.             alt="Valid CSS!" />
  291.     </a>
  292. </p>
  293.     </footer>
  294.   </div>
  295.  
  296. </body>
  297. </html>
  298.  
  299. //upload.php
  300. <!DOCTYPE html>
  301. <html lang="en">
  302. <head>
  303.   <meta charset="UTF-8">
  304.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  305.   <title>Post Uploaded!</title>
  306.  
  307.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  308.  
  309.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  310. </head>
  311. <body class="box">
  312.  
  313. <!--Navigation bar-->
  314.  
  315. <div>
  316.     <nav>
  317.       <ul>
  318.         <li><a href="../index.html">Home</a></li>
  319.         <li><a href="gallery.php">Gallery</a></li>
  320.         <li><a href="../html/upload.html">Create Post</a></li>
  321.         <li><a href="../html/contact.html">Contact Us</a></li>
  322.         <li><a href="../html/reg_form.html">Register</a></li>
  323.         <li><a href="#">Login</a></li>
  324.       </ul>
  325.       <input type="text" placeholder="Search" id="search">
  326.     </nav>
  327.   </div>
  328.  
  329. <?php
  330.  
  331. //store our connection credentials in variables;  
  332. $server = 'localhost';  
  333. $user = 'root';  
  334. $pass = '';
  335. //there is no password for the my current setup of MySQL  
  336. $dbase = 'assignment1';      
  337. //make the actual connection to myaql and the chosen database  
  338. $conn = mysqli_connect($server, $user, $pass, $dbase);  
  339.  //if the connection failed print error message
  340.  if (!$conn) {    
  341.     die('Could not connect to database because: ' . mysqli_connect_error());    
  342.  }  
  343.   //else echo "You are successfully connected to $dbase <br>";
  344.  
  345. //inputs from the form upload.html
  346. $caption = $_POST["caption"];
  347. $author = $_POST["author"];
  348.  
  349. /*
  350. Code for the image upload comes from:
  351.   W3Schools. (n.d.). PHP File Upload. PHP file upload. https://www.w3schools.com/php/php_file_upload.asp
  352. Retrieved 21st Oct. 2023.*/
  353.  
  354.   //upload image
  355. $target_dir = "../user_images/";
  356. $target_file = $target_dir . basename($_FILES["user_upload"]["name"]);
  357. $uploadOk = 1;
  358. $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  359.  
  360. // Check if image file is a actual image or fake image
  361. /*if(isset($_POST["submit"])) {
  362.   $check = getimagesize($_FILES["user_upload"]["tmp_name"]);
  363.   if($check !== false) {
  364.     echo "File is an image - " . $check["mime"] . ".";
  365.     $uploadOk = 1;
  366.   } else {
  367.     echo "File is not an image.";
  368.     $uploadOk = 0;
  369.   }
  370. }*/
  371.  
  372. // Check if file already exists
  373. /*if (file_exists($target_file)) {
  374.   echo "Sorry, file already exists.";
  375.   $uploadOk = 0;
  376. }*/
  377.  
  378. // Check file size
  379. if ($_FILES["user_upload"]["size"] > 500000) {
  380.   echo "Sorry, your file is too large.";
  381.   $uploadOk = 0;
  382. }
  383.  
  384. // Allow certain file formats
  385. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  386. && $imageFileType != "gif" ) {
  387.   echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  388.   $uploadOk = 0;
  389. }
  390.  
  391. // Check if $uploadOk is set to 0 by an error
  392. if ($uploadOk == 0) {
  393.   echo "Sorry, your file was not uploaded.";
  394. // if everything is ok, try to upload file
  395. } else {
  396.   if (move_uploaded_file($_FILES["user_upload"]["tmp_name"], $target_file)) {
  397.     echo "The file ". htmlspecialchars( basename( $_FILES["user_upload"]["name"])). " has been uploaded.";
  398.   } else {
  399.     echo "Sorry, there was an error uploading your file.";
  400.   }
  401. }
  402.  
  403. //insert into database
  404. //use PHP variables as input to MqSQL query.
  405.  
  406. $qry = "INSERT INTO post_info (picture, caption, author) VALUES ('$target_file', '$caption', '$author')";
  407.  
  408. //only quote text data
  409. //use double quotes on the outside and single quotes on the inside
  410.  
  411. //execute the query    
  412. $result = mysqli_query($conn, $qry);
  413.  
  414. //check on the success of the query
  415. if($result) echo 'record successfully inserted.<br><br>';
  416. else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';
  417.  
  418. //close the connection
  419. mysqli_close($conn);
  420. ?>
  421.  
  422. <p>You can see your post on <a href='gallery.php'>Gallery</a>.</p>
  423.  
  424. <!--Footer-->
  425.  
  426. <div class="footer">
  427.     <footer>
  428.       <p>&copy; 2023 PhotoShare</p>
  429.       <p>
  430.     <a href="http://jigsaw.w3.org/css-validator/check/referer">
  431.         <img style="border:0;width:88px;height:31px"
  432.             src="http://jigsaw.w3.org/css-validator/images/vcss"
  433.             alt="Valid CSS!" />
  434.     </a>
  435. </p>
  436.     </footer>
  437.   </div>
  438.  
  439. </body>
  440. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement