Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('db.php');
- $upload_dir = 'uploads/';
- if (isset($_POST['Submit'])) {
- $title = $_POST['title'];
- $text = $_POST['text'];
- $content = $_POST['content'];
- $imgName = $_FILES['image']['name'];
- $imgTmp = $_FILES['image']['tmp_name'];
- $imgSize = $_FILES['image']['size'];
- if(empty($title)){
- $errorMsg = 'Please add a title';
- }elseif(empty($text)){
- $errorMsg = 'Please input a text';
- }elseif(empty($content)){
- $errorMsg = 'Please input a content to display';
- }else{
- $imgExt = strtolower(pathinfo($imgName, PATHINFO_EXTENSION));
- $allowExt = array('jpeg', 'jpg', 'png', 'gif');
- $userPic = time().'_'.rand(1000,9999).'.'.$imgExt;
- if(in_array($imgExt, $allowExt)){
- if($imgSize < 5000000){
- move_uploaded_file($imgTmp ,$upload_dir.$userPic);
- }else{
- $errorMsg = 'Image too large';
- }
- }else{
- $errorMsg = 'Please select a valid image';
- }
- }
- if(!isset($errorMsg)){
- $sql = "insert into benefit_keys(title, text, content, image)
- values('".$title."', '".$text."', '".$content."', '".$userPic."')";
- $result = mysqli_query($conn, $sql);
- if($result){
- $successMsg = 'New record added successfully';
- header('Location: admin.php');
- }else{
- $errorMsg = 'Error '.mysqli_error($conn);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement