Advertisement
thotfrnk

final project part1.php

Feb 1st, 2024
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.34 KB | None | 0 0
  1. //index.php
  2. <?php
  3. require('php/session.php');
  4. ?>
  5.  
  6. <!DOCTYPE html>
  7. <html lang="en">
  8. <head>
  9.   <meta charset="UTF-8">
  10.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11.   <title>Home</title>
  12.  
  13.   <link href="css/style.css" rel="stylesheet" type="text/css">
  14.  
  15.   <link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
  16.   <!--favicon was made by [user thotfrnk] using Adobe logo maker-->
  17. </head>
  18. <body>
  19.  
  20. <!--Navigation bar-->
  21.  
  22. <?php
  23. if (isset($_SESSION['user'])) {
  24.   require('php/home_member_nav.php');
  25. }
  26. else {
  27. require('php/home_guest_nav.php');
  28. }
  29. ?>
  30.  
  31. <div class="header_center"> <h1>Welcome to PhotoShare</h1> </div>
  32.  
  33. <div class="about">
  34.  
  35.  <!--All images used came from pexels.com-->
  36.  
  37.  <!--Wheeler, J. (2013, September 2). Symmetrical Photography of clouds covered blue sky - pexels. https://www.pexels.com/photo/symmetrical-photography-of-clouds-covered-blue-sky-1486974/ . Retrieved 15th Oct. 2023.-->
  38.  
  39.  <img src="images/pexels-james-wheeler.jpg" width="200" height="250" id="img1" alt="A shot of a lake with the sky reflected in it. The sky has clouds and a pinkish colour to it. In the backgroud grassy fields and trees can be seen.">
  40.  
  41.   <div id="paragraph1">
  42.   <p>PhotoShare aims to build a community for aspiring photographers.
  43.   </p>
  44.  
  45.   </div>
  46.  
  47.   <div id="paragraph2">
  48.  
  49.   <!--Lastovich, T. (2017, March 4). Brown wooden dock surrounded with green grass near mountain under white ... https://www.pexels.com/photo/brown-wooden-dock-surrounded-with-green-grass-near-mountain-under-white-clouds-and-blue-sky-at-daytime-808465/ . Retrieved 15th Oct. 2023.-->
  50.  
  51.   <img src="images/pexels-tyler-lastovich.jpg" width="200" height="250" id="img2" alt="A shot of a mountainous trail, with dried grass on both sides of the wooden trail.">
  52.  
  53.   <p>We want to foster talent in a safe environment and inspire photographers to aim high.</p>
  54.  
  55.   </div>
  56.  
  57.   <br>
  58.  
  59.   <div id="paragraph3">
  60.  
  61.     <p>On PhotoShare you will be able to make posts, comment, and interact with other photographers.</p>
  62.  
  63.   <!--Gould, D. (2016, November 21). Scenic view of river · Free Stock Photo - PEXELS. https://www.pexels.com/photo/scenic-view-of-river-325807/ . Retrieved 15th Oct. 2023.-->
  64.  
  65.   <img src="images/pexels-dom-gould.jpg" width="400" height="250" id="img3" alt="A shot of a crystal blue lake in between rocky land and it is surrounded by trees.">
  66.  
  67.   <!--Berger, S. (2015, June 7). Scenic view of mountains during Dawn · free stock photo - PEXELS. https://www.pexels.com/photo/scenic-view-of-mountains-during-dawn-1266810/ . Retrieved 15th Oct. 2023.-->
  68.  
  69.   <img src="images/pexels-simon-berger.jpg" width="200" height="250" id="img4" alt="A shot at the top of a mountain, in the foreground flowers growing from its surface can be seen, the middle ground shows mountains and the background is the sun hidden behind cloud coverage.">
  70.  
  71.   <!--Bartus, D. (2018, June 12). Photo lavender flower field under Pink Sky · free stock photo - PEXELS. https://www.pexels.com/photo/photo-lavender-flower-field-under-pink-sky-1166209/ . Retrieved 15th Oct. 2023.-->
  72.  
  73.   <img src="images/pexels-david-bartus.jpg" width="400" height="250" id="img5" alt="A shot of a lavender field, showing rows and rows and bright purple lavender, set with the pinkish clounds and blue sky.">
  74.  
  75.   </div>
  76.  
  77. </div>
  78.  
  79. <!--Footer
  80. will turn this into a incl. php file!-->
  81.  
  82. <div class="footer">
  83. <footer>
  84.   <p>&copy; 2023 PhotoShare</p>
  85. </footer>
  86. </div>
  87.  
  88. </body>
  89. </html>
  90.  
  91. //comment_display.php
  92. <!--file to be included on the gallery.php file-->
  93.   <?php
  94.   //database connection
  95.   require('db_connect.php');
  96.  
  97.  
  98.   //Create the query string
  99.   $query1 = "select * from comment_section";
  100.  
  101.   //execute the query
  102.   $result1 = mysqli_query($conn, $query1);
  103.   if ($result1) {
  104.  
  105.     if (mysqli_num_rows($result1) > 0) {
  106.  
  107.       while ($row1 = mysqli_fetch_assoc($result1)) {
  108.  
  109.         //comparing the post_id in the comment_section table to the post_info table to ensure the comments are being displayed on the correct post
  110.         if($row1['post_id'] == $row['post_id']) {
  111.  
  112.         //echo statement to output the comments and how it will be formatted in html+css
  113.           echo "
  114.        <div id=\"comment\">
  115.        <div class=\"author\"><strong>$row1[username]</strong></div>
  116.        <br>
  117.        <div class=\"caption\">$row1[comment]</div>
  118.        <br>
  119.  
  120.        <div class=\"date\"><strong>$row1[comment_date]</strong></div>
  121.        </div>
  122.        <br><br>";
  123.  
  124.       }
  125.     }
  126.       //end while loop
  127.  
  128.     }
  129.     //end if 1 or more rows
  130.  
  131.     else
  132.       echo "<br>No comments avaliable.";
  133.   }
  134.   ?>
  135.  
  136. //comment_frm.php
  137. <!--file to be included on gallery.php-->
  138. <?php
  139. //if statement to ensure only users who are logged in will be allowed to view and use the post comment form
  140. if(isset($_SESSION['user'])) {
  141.   //echo statement to display the comment form
  142.   echo "<form id='comment_frm'
  143.  action='comment_upload.php'
  144.  method='post'>
  145.  
  146.    <textarea name='comment'></textarea>
  147.  
  148.    <input type='hidden' name='post_id' id='post_id' value='".$row['post_id']. "'>
  149.  
  150.    <input type='submit' name='submit' value='Comment'>
  151.  </form>";
  152. }
  153. ?>
  154.  
  155. //comment_upload.php
  156. <?php
  157. //session info
  158. require('session.php');
  159. ?>
  160.  
  161. <!DOCTYPE html>
  162. <html lang="en">
  163. <head>
  164.   <meta charset="UTF-8">
  165.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  166.   <title>Comment Posted</title>
  167.  
  168.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  169.  
  170. <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  171. </head>
  172. <body>
  173. <?php
  174. //navigation bar
  175. require('member_nav.php');
  176.  
  177. //database connection
  178. require('db_connect.php');
  179.  
  180. if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST["submit"])) {
  181.  
  182.   $comment = $_POST["comment"];
  183.   $post_id = $_POST["post_id"];
  184.  
  185. //insert into database
  186. //use PHP variables as input to MqSQL query.
  187.  
  188. $qry = "INSERT INTO comment_section (comment, username, post_id) VALUES ('$comment', '$_SESSION[user]', '$post_id')";
  189.  
  190. //execute the query    
  191. $result2 = mysqli_query($conn, $qry);
  192.  
  193. //check on the success of the query
  194. if(!$result2) {
  195. echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';
  196. }
  197.  
  198. //close the connection
  199. mysqli_close($conn);
  200. }
  201. ?>
  202.  
  203. <h1 class="header_center">Your Comment has been posted.</h1>
  204.  
  205. <p>You can view your comment <a href="gallery.php">here</a>.</p>
  206.  
  207. <?php
  208.  //footer
  209.  require('footer.php');
  210.  ?>
  211. </body>
  212. </html>
  213.  
  214. //contact.php
  215. <?php
  216. //session information
  217. require('session.php');
  218. ?>
  219.  
  220. <!--this file will display after contact form is submitted and it will input the data into the databse-->
  221.  
  222. <!DOCTYPE html>
  223. <html lang="en">
  224. <head>
  225.   <meta charset="UTF-8">
  226.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  227.   <title>Welcome!</title>
  228.  
  229.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  230.  
  231.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  232.  
  233. </head>
  234. <body>
  235.  
  236.   <?php
  237.   //navigation bar
  238.   //guests and members will see different nav bars.
  239. if (isset($_SESSION['user'])) {
  240.   require('member_nav.php');
  241. }
  242. else {
  243. require('guest_nav.php');
  244. }
  245. ?>
  246.  
  247.   <br><br>
  248.  
  249.   <?php
  250.  
  251. //storing information from the form in php variables
  252. $username = $_POST["user_name"];
  253. $email = $_POST["email"];
  254. $feedback = $_POST["feedback"];
  255.  
  256. //database connection
  257. require('db_connect.php');
  258.  
  259.   //use PHP variables as input to MqSQL query.
  260. $qry = "INSERT INTO user_feedback (username, email, feedback) VALUES ('$username', '$email', '$feedback');";  
  261.  
  262. //execute the query    
  263. $result = mysqli_query($conn, $qry);
  264.  
  265. //check on the success of the query
  266.  if(!$result) echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';  
  267.  mysqli_close($conn);
  268.  
  269.   ?>
  270.  
  271. <p>Thank you for your feedback! We will get back to you soon.</p>
  272.  
  273.  <?php
  274.  //footer
  275.  require('footer.php');
  276.  ?>
  277.  
  278. </body>
  279. </html>
  280.  
  281. //db_connect.php
  282. <!--this file will be called whenever a database connection is needed-->
  283. <?php
  284. //store our connection credentials in variables;
  285. //names removed for privacy
  286. $server = '';  
  287. $user = '';  
  288. $pass = '';
  289. $dbase = '';      
  290. //making the actual connection to mysql and the chosen database  
  291. $conn = mysqli_connect($server, $user, $pass, $dbase);  
  292.  //if the connection failed print error message
  293.  if (!$conn) {    
  294.     die('Could not connect to database because: ' . mysqli_connect_error());    
  295.  }  
  296. ?>
  297.  
  298. //edit_profile.php
  299. <?php
  300. //session info
  301. require('session.php');
  302. ?>
  303.  
  304. <!--this is a member's only page to edit their profile-->
  305.  
  306. <!DOCTYPE html>
  307. <html lang="en">
  308. <head>
  309.   <meta charset="UTF-8">
  310.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  311.   <title>Edit Profile</title>
  312.  
  313.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  314.  
  315.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  316. </head>
  317. <body>
  318.   <?php
  319.   //navigation bar
  320.     require('member_nav.php');
  321.  
  322.   //initalizing php variables to hold form data
  323.  
  324. $username = $email = $pword = $fname = $lname = $age = $phone = "";
  325.  
  326. $userErr = $emailErr = $pwordErr = $fnErr = $lnErr = $ageErr = $phoneErr = "";
  327.  
  328.  
  329.  
  330. //database connection  
  331. require('db_connect.php');
  332.  
  333.   //creating query string
  334.   $query = "select * from user_info where username = '$_SESSION[user]'";
  335.  
  336.   //execute the query
  337.  $result = mysqli_query($conn, $query);
  338.  if ($result) {
  339.  
  340.    if (mysqli_num_rows($result) > 0) {
  341.  
  342.      while ($row = mysqli_fetch_assoc($result)) {
  343.  
  344.       //storing database info to input it into the form
  345.       $username = $row['username'];
  346.        $email = $row['email'];
  347.        $fname = $row['fname'];
  348.        $lname = $row['lname'];
  349.        $age = $row['age'];
  350.        $phone = $row['phone_num'];
  351.  
  352.      }
  353.      //end while loop
  354.  
  355.    }
  356.    //end if 1 or more rows
  357.  
  358.    else
  359.      echo "<br>No posts avaliable.";
  360.  }
  361.  mysqli_close($conn);
  362.   ?>
  363.   <br>
  364.  
  365.   <h1 class="header_center">Edit Profile</h1>
  366.  
  367.   <div class="update_form">
  368.     <form
  369.     id="update"
  370.     action="update_form.php"
  371.     onsubmit="return validate();"
  372.     method="post">
  373.  
  374.       <fieldset>
  375.         <legend><strong>Account Information:</strong></legend>
  376.  
  377.         <input type="text" name="user_name" id="user_name" placeholder="Username" value="<?php echo $username; ?>">
  378.  
  379.         <span id="userErr" class="error"> <?php echo $userErr; ?> </span>
  380.  
  381.         <br><br>
  382.  
  383.         <input type="text" name="email" id="email" placeholder="Email" value="<?php echo $email; ?>">
  384.  
  385.         <span id="emailErr" class="error"><?php echo $emailErr; ?></span>
  386.  
  387.         <br><br>
  388.  
  389.         <input type="text" name="pword" id="pword" placeholder="Password" value="<?php echo $pword; ?>">
  390.  
  391.         <span id="pwordErr" class="error"> <?php echo $pwordErr; ?> </span>
  392.  
  393.       </fieldset>
  394.  
  395.       <br>
  396.  
  397.       <fieldset>
  398.         <legend><strong>Personal Information:</strong></legend>
  399.        
  400.         <input type="text" name="fname" id="fname" placeholder="First Name" value="<?php echo $fname; ?>">
  401.  
  402.         <span id="fnErr" class="error"> <?php echo $fnErr; ?> </span>
  403.  
  404.         <br><br>
  405.  
  406.         <input type="text" name="lname" id="lname" placeholder="Last Name" value="<?php echo $lname; ?>">
  407.  
  408.         <span id="lnErr" class="error"> <?php echo $lnErr; ?> </span>
  409.  
  410.         <br><br>
  411.  
  412.         <input type="text" name="age" id="age" placeholder="Age" value="<?php echo $age; ?>">
  413.  
  414.         <span id="ageErr" class="error"> <?php echo $ageErr; ?> </span>
  415.  
  416.         <br><br>
  417.  
  418.         <input type="text" name="phone" id="phone" placeholder="Phone Number" value="<?php echo $phone; ?>">
  419.  
  420.         <span id="phoneErr" class="error"> <?php echo $phoneErr; ?> </span>
  421.       </fieldset>
  422.  
  423.       <br>
  424.  
  425.       <input type="submit" name="update" value="UPDATE">
  426.  
  427.     </form>
  428.   </div>
  429.  
  430.   <?php
  431.  //footer
  432.  require('footer.php');
  433.  ?>
  434.  
  435.   <script type="text/javascript" src="../javascript/myJS.js" ></script>
  436.  
  437. </body>
  438. </html>
  439.  
  440. //footer.php
  441. <!--footer info to include on all php files that will be displayed-->
  442. <footer>
  443. <div class="footer">
  444.     <footer>
  445.       <p>&copy; 2023 PhotoShare</p>
  446.     </footer>
  447.   </div>
  448. </footer>
  449.  
  450. //gallery.php
  451. <?php
  452. //session info
  453. require('session.php');
  454. ?>
  455.  
  456. <!--this is the gallery page that will display all the user posts from the post_info table in the database-->
  457.  
  458. <!DOCTYPE html>
  459. <html lang="en">
  460. <head>
  461.   <meta charset="UTF-8">
  462.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  463.   <title>Gallery</title>
  464.  
  465.   <link href="../css/style.css" rel="stylesheet" type="text/css">
  466.  
  467.   <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
  468.  
  469. </head>
  470. <body>
  471.  
  472. <!--Navigation bar-->
  473. <?php
  474. if (isset($_SESSION['user'])) {
  475.   require('member_nav.php');
  476. }
  477. else {
  478. require('guest_nav.php');
  479. }
  480. ?>
  481.  
  482.   <br><br>
  483.  
  484.   <h1 class="header_center">User Posts</h1>
  485.  
  486.   <!--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.-->
  487.  
  488.  <?php
  489.  
  490. //database connection
  491. require('db_connect.php');
  492.  
  493.  
  494.  //Create the query string
  495.  $query = "select * from post_info";
  496.  
  497.  //execute the query
  498.  $result = mysqli_query($conn, $query);
  499.  if ($result) {
  500.  
  501.    if (mysqli_num_rows($result) > 0) {
  502.  
  503.      while ($row = mysqli_fetch_assoc($result)) {
  504.  
  505.       //to display the gallery
  506.       echo "<div class=\"gallery\">
  507.  
  508.       <div class=\"pic\"><img src='$row[picture]'  alt='User Upload' width='500' height='333'></div>
  509.       <input type='hidden' name='post_id' value='$row[post_id]'>
  510.  
  511.       <br>
  512.  
  513.       <div class=\"caption\">$row[caption]</div>
  514.  
  515.       <div class=\"author\"><strong>$row[author]</strong></div>
  516.  
  517.       <div class=\"date\"><strong>$row[post_date]</strong></div>
  518.       <br><br>";
  519.  
  520.        //comment form for users to write comments on posts
  521.        include('comment_frm.php');
  522.  
  523.        //to format the comment section
  524.        echo "<div id=\"comment_section\">";
  525.  
  526.        //to display the comments from the comment_section table in the database
  527.        include('comment_display.php');
  528.  
  529.        //to close off the div tags from the prev. echo statements
  530.        echo "</div>";
  531.        
  532.       echo "</div>";
  533.  
  534.      }
  535.      //end while loop
  536.  
  537.    }
  538.    //end if 1 or more rows
  539.  
  540.    else
  541.      echo "<br>No posts avaliable.";
  542.  }
  543.  mysqli_close($conn);
  544.  ?>
  545.  
  546. <?php
  547.  //footer
  548.  require('footer.php');
  549.  ?>
  550. </body>
  551. </html>
  552.  
  553. //guest_nav.php
  554. <!--this will display on all the php files for the guest (non-registered users) who wish to navigate photoshare-->
  555.   <div class="nav1">
  556.     <ul>
  557.       <li id="home"><a href="../index.php"><img src="../images/camera.png" height="32" width="32" alt="camera icon"> | PhotoShare</a></li>
  558.       <!--camera icon:
  559.     Flaticon. (2019, July 24). Camera free icons designed by Freepik. Flaticon. https://www.flaticon.com/free-icon/camera_1998342 -->
  560.       <li id="log"><a href="../html/login.html">Login</a></li>
  561.       <li id="reg"><a href="reg_form.php">Sign Up</a></li>
  562.     </ul>
  563.   </div>
  564.  
  565.   <div class="nav2">
  566.     <ul>
  567.       <li><a href="gallery.php">Gallery</a></li>
  568.       <li><a href="../html/contact.html">Contact</a></li>
  569.     </ul>
  570.     <form method="post" action="search.php">
  571.  
  572.     <input type="text" placeholder="Search PhotoShare" name="search" id="search">
  573.  
  574.     <input type="submit" name="search_btn" value="Search" id="search_btn">
  575. </form>
  576.   </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement