Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Movies review</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="description" content="" />
- <meta name="keywords" content="" />
- <!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
- <script src="js/jquery.min.js"></script>
- <script src="js/jquery.poptrox.min.js"></script>
- <script src="js/skel.min.js"></script>
- <script src="js/init.js"></script>
- </script>
- <noscript>
- <link rel="stylesheet" href="css/skel-noscript.css" />
- <link rel="stylesheet" href="css/style.css" />
- </noscript>
- </head>
- <body>
- <?php
- $bimage = "";
- if(isset($_FILES["file"]["type"]))
- {
- $validextensions = array("jpeg", "jpg", "png");
- $temporary = explode(".", $_FILES["file"]["name"]);
- $file_extension = end($temporary);
- if ((($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg"))
- && in_array($file_extension, $validextensions))
- {
- if ($_FILES["file"]["error"] > 0)
- {
- }
- else
- {
- if (file_exists("images/" . $_FILES["file"]["name"]))
- {
- }
- else
- {
- $sourcePath = $_FILES['file']['tmp_name']; // Storing source path of the file in a variable
- $targetPath = "images/".$_FILES['file']['name']; // Target path where file is to be stored
- move_uploaded_file($sourcePath,$targetPath) ; // Moving Uploaded file
- $bimage = $_FILES["file"]["name"];
- }
- }
- }
- else
- {
- }
- }
- ?>
- <?php
- //including the database connection file
- include "connect.php";
- $conn = mysqli_connect($servername, $username, $password, $dname);
- if(isset($_POST['bname'])) {
- $bname = $_POST['bname'];
- $btitle = $_POST['btitle'];
- $bdesc = $_POST['bdesc'];
- }
- // checking empty fields
- if(empty($bname) || empty($btitle) ||empty($bimage) || empty($bdesc)) {
- if(empty($bname)) {
- echo "<font color='red'>Name field is empty.</font><br/>";
- }
- if(empty($btitle)) {
- echo "<font color='red'>Title field is empty.</font><br/>";
- }
- if(empty($bimage)) {
- echo "<font color='red'>Image field is empty.</font><br/>";
- }
- if(empty($bdesc)) {
- echo "<font color='red'>Description field is empty.</font><br/>";
- }
- //link to the previous page
- echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
- } else {
- // if all the fields are filled (not empty)
- //insert data to database
- $bdesc = str_replace("'","''",$bdesc);
- $result = mysqli_query($conn, "INSERT INTO blog(bname,bimage,btitle,bdesc) VALUES('$bname','$bimage','$btitle','$bdesc')");
- if ($result)
- {
- //display success message
- echo "<font color='green'>Data added successfully.";
- echo "<br/><a href='add1.php'>View Result</a>";
- }
- else
- {
- echo mysqli_error($conn);
- if ($conn) echo "no data base";
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement