Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //contact.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Welcome!</title>
- <link href="../css/style.css" rel="stylesheet" type="text/css">
- <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
- </head>
- <body class="box">
- <!--Navigation bar-->
- <div>
- <nav>
- <ul>
- <li><a href="../index.html">Home</a></li>
- <li><a href="gallery.php">Gallery</a></li>
- <li><a href="../html/upload.html">Create Post</a></li>
- <li><a href="../html/contact.html">Contact Us</a></li>
- <li><a href="../html/reg_form.html">Register</a></li>
- <li><a href="#">Login</a></li>
- </ul>
- <input type="text" placeholder="Search" id="search">
- </nav>
- </div>
- <br><br>
- <?php
- $username = $_POST["user_name"];
- $email = $_POST["email"];
- $feedback = $_POST["feedback"];
- //store our connection credentials in variables;
- $server = 'localhost';
- $user = 'root';
- $pass = '';
- //there is no password for the my current setup of MySQL
- $dbase = 'assignment1';
- //make the actual connection to myaql and the chosen database
- $conn = mysqli_connect($server, $user, $pass, $dbase);
- //if the connection failed print error message
- if (!$conn) {
- die('Could not connect to database because: ' . mysqli_connect_error());
- }
- /*else echo "You are successfully connected to $dbase <br>";*/
- //use PHP variables as input to MqSQL query.
- $qry = "INSERT INTO user_feedback (username, email, feedback) VALUES ('$username', '$email', '$feedback');";
- //only quote text data
- //use double quotes on the outside and single quotes on the inside
- //execute the query
- $result = mysqli_query($conn, $qry);
- //check on the success of the query
- if(!$result) echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';
- /*echo 'record successfully inserted.<br><br>';*/
- /*else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';*/
- //close the connection
- mysqli_close($conn);
- ?>
- <p>Thank you for your feedback! We will get back to you soon.</p>
- <!--Footer-->
- <div class="footer">
- <footer>
- <p>© 2023 PhotoShare</p>
- </footer>
- </div>
- </body>
- </html>
- //gallery.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Gallery</title>
- <link href="../css/style.css" rel="stylesheet" type="text/css">
- <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
- </head>
- <body class="box">
- <!--Navigation bar-->
- <div>
- <nav>
- <ul>
- <li><a href="../index.html">Home</a></li>
- <li><a href="gallery.php">Gallery</a></li>
- <li><a href="../html/upload.html">Create Post</a></li>
- <li><a href="../html/contact.html">Contact Us</a></li>
- <li><a href="../html/reg_form.html">Register</a></li>
- <li><a href="#">Login</a></li>
- </ul>
- <input type="text" placeholder="Search" id="search">
- </nav>
- </div>
- <br><br>
- <h1 class="header_center">User Posts</h1>
- <!--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.-->
- <?php
- //store our connection credentials in variables;
- $server = 'localhost';
- $user = 'root';
- $pass = '';
- //there is no password for the my current setup of MySQL
- $dbase = 'assignment1';
- //make the actual connection to myaql and the chosen database
- $conn = mysqli_connect($server, $user, $pass, $dbase);
- //if the connection failed print error message
- if (!$conn) {
- die('Could not connect to database because: ' . mysqli_connect_error());
- }
- //else echo "You are successfully connected to $dbase <br>";
- //Create the query string
- $query = "select * from post_info";
- //execute the query
- $result = mysqli_query($conn, $query);
- if ($result) {
- if (mysqli_num_rows($result) > 0) {
- // if we are in this block it means that $result was NOT false and it contained
- // at least one row of data... so let's process the data one row at a time
- while ($row = mysqli_fetch_assoc($result)) {
- // if we are in this inner block it means that we just successfully retrieved
- // a row of data from the resultset held in $result. We can embed this in
- // our HTML page as shown below
- echo "<div class=\"gallery\">
- <img src='$row[picture]' alt='User Upload' width='500' height='333'>
- <br>
- <div class=\"caption\">$row[caption]</div>
- <div class=\"author\"><strong>$row[author]</strong></div>
- <div class=\"date\">$row[post_date]</div>
- </div>";
- }
- //end while loop
- }
- //end if 1 or more rows
- else
- echo "<br>No rows returned";
- }
- mysqli_close($conn);
- ?>
- <!--Footer-->
- <div class="footer">
- <footer>
- <p>© 2023 PhotoShare</p>
- <p>
- <a href="http://jigsaw.w3.org/css-validator/check/referer">
- <img style="border:0;width:88px;height:31px"
- src="http://jigsaw.w3.org/css-validator/images/vcss"
- alt="Valid CSS!" />
- </a>
- </p>
- </footer>
- </div>
- </body>
- </html>
- //register.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Welcome!</title>
- <link href="../css/style.css" rel="stylesheet" type="text/css">
- <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
- </head>
- <body class="box">
- <!--Navigation bar-->
- <div>
- <nav>
- <ul>
- <li><a href="../index.html">Home</a></li>
- <li><a href="gallery.php">Gallery</a></li>
- <li><a href="../html/upload.html">Create Post</a></li>
- <li><a href="../html/contact.html">Contact Us</a></li>
- <li><a href="../html/reg_form.html">Register</a></li>
- <li><a href="#">Login</a></li>
- </ul>
- <input type="text" placeholder="Search" id="search">
- </nav>
- </div>
- <br><br>
- <?php
- $username = $_POST["user_name"];
- $email = $_POST["email"];
- $pword = $_POST["pword"];
- $fname = $_POST["fname"];
- $lname = $_POST["lname"];
- $age = $_POST["age"];
- $phone = $_POST["phone"];
- echo "<h1>Welcome to PhotoShare $username!</h1>
- <br>";
- //store our connection credentials in variables;
- $server = 'localhost';
- $user = 'root';
- $pass = '';
- //there is no password for the my current setup of MySQL
- $dbase = 'assignment1';
- //make the actual connection to myaql and the chosen database
- $conn = mysqli_connect($server, $user, $pass, $dbase);
- //if the connection failed print error message
- if (!$conn) {
- die('Could not connect to database because: ' . mysqli_connect_error());
- }
- /*else echo "You are successfully connected to $dbase <br>";*/
- //use PHP variables as input to MqSQL query.
- $qry = "INSERT INTO user_info (username, email, pword, fname, lname, age, phone_num) VALUES ('$username', '$email', '$pword', '$fname', '$lname', '$age', '$phone');";
- //only quote text data
- //use double quotes on the outside and single quotes on the inside
- //execute the query
- $result = mysqli_query($conn, $qry);
- //check on the success of the query
- if(!$result) echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';
- /*echo 'record successfully inserted.<br><br>';*/
- /*else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';*/
- //close the connection
- mysqli_close($conn);
- ?>
- <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>
- <!--Footer-->
- <div class="footer">
- <footer>
- <p>© 2023 PhotoShare</p>
- <p>
- <a href="http://jigsaw.w3.org/css-validator/check/referer">
- <img style="border:0;width:88px;height:31px"
- src="http://jigsaw.w3.org/css-validator/images/vcss"
- alt="Valid CSS!" />
- </a>
- </p>
- </footer>
- </div>
- </body>
- </html>
- //upload.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Post Uploaded!</title>
- <link href="../css/style.css" rel="stylesheet" type="text/css">
- <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon-32x32.png">
- </head>
- <body class="box">
- <!--Navigation bar-->
- <div>
- <nav>
- <ul>
- <li><a href="../index.html">Home</a></li>
- <li><a href="gallery.php">Gallery</a></li>
- <li><a href="../html/upload.html">Create Post</a></li>
- <li><a href="../html/contact.html">Contact Us</a></li>
- <li><a href="../html/reg_form.html">Register</a></li>
- <li><a href="#">Login</a></li>
- </ul>
- <input type="text" placeholder="Search" id="search">
- </nav>
- </div>
- <?php
- //store our connection credentials in variables;
- $server = 'localhost';
- $user = 'root';
- $pass = '';
- //there is no password for the my current setup of MySQL
- $dbase = 'assignment1';
- //make the actual connection to myaql and the chosen database
- $conn = mysqli_connect($server, $user, $pass, $dbase);
- //if the connection failed print error message
- if (!$conn) {
- die('Could not connect to database because: ' . mysqli_connect_error());
- }
- //else echo "You are successfully connected to $dbase <br>";
- //inputs from the form upload.html
- $caption = $_POST["caption"];
- $author = $_POST["author"];
- /*
- Code for the image upload comes from:
- W3Schools. (n.d.). PHP File Upload. PHP file upload. https://www.w3schools.com/php/php_file_upload.asp
- Retrieved 21st Oct. 2023.*/
- //upload image
- $target_dir = "../user_images/";
- $target_file = $target_dir . basename($_FILES["user_upload"]["name"]);
- $uploadOk = 1;
- $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
- // Check if image file is a actual image or fake image
- /*if(isset($_POST["submit"])) {
- $check = getimagesize($_FILES["user_upload"]["tmp_name"]);
- if($check !== false) {
- echo "File is an image - " . $check["mime"] . ".";
- $uploadOk = 1;
- } else {
- echo "File is not an image.";
- $uploadOk = 0;
- }
- }*/
- // Check if file already exists
- /*if (file_exists($target_file)) {
- echo "Sorry, file already exists.";
- $uploadOk = 0;
- }*/
- // Check file size
- if ($_FILES["user_upload"]["size"] > 500000) {
- echo "Sorry, your file is too large.";
- $uploadOk = 0;
- }
- // Allow certain file formats
- if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
- && $imageFileType != "gif" ) {
- echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
- $uploadOk = 0;
- }
- // Check if $uploadOk is set to 0 by an error
- if ($uploadOk == 0) {
- echo "Sorry, your file was not uploaded.";
- // if everything is ok, try to upload file
- } else {
- if (move_uploaded_file($_FILES["user_upload"]["tmp_name"], $target_file)) {
- echo "The file ". htmlspecialchars( basename( $_FILES["user_upload"]["name"])). " has been uploaded.";
- } else {
- echo "Sorry, there was an error uploading your file.";
- }
- }
- //insert into database
- //use PHP variables as input to MqSQL query.
- $qry = "INSERT INTO post_info (picture, caption, author) VALUES ('$target_file', '$caption', '$author')";
- //only quote text data
- //use double quotes on the outside and single quotes on the inside
- //execute the query
- $result = mysqli_query($conn, $qry);
- //check on the success of the query
- if($result) echo 'record successfully inserted.<br><br>';
- else echo 'Error occurred: ' . mysqli_error($conn) . '<br><br>';
- //close the connection
- mysqli_close($conn);
- ?>
- <p>You can see your post on <a href='gallery.php'>Gallery</a>.</p>
- <!--Footer-->
- <div class="footer">
- <footer>
- <p>© 2023 PhotoShare</p>
- <p>
- <a href="http://jigsaw.w3.org/css-validator/check/referer">
- <img style="border:0;width:88px;height:31px"
- src="http://jigsaw.w3.org/css-validator/images/vcss"
- alt="Valid CSS!" />
- </a>
- </p>
- </footer>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement