-5

Hi i have built a uploader that is supposed to upload some data plus a image.

The form shows on the webpage with no errors but will not upload.

Here is a screen shot also the code is attached too.

http://simplicity-designs.tk/images/Screenshot%20%28104%29.png

  <?php
    include("includes/connect.php");

    if(isset($_POST['submit'])){

     $title = $_POST['title'];
     $date = date('d-m-y'); 
     $author = $_POST['author'];    
     $image = $_FILES['image']['name']; 
     $keywords = $_POST['keywords'];    
     $content = $_POST['content'];
     $image_tmp = $_FILES['image']['tmp_name'];

     if($title == '' or $author == '' or $keywords == '' or $content == ''){
        echo "
            <script>
                alert('PLEASE CHECK YOUR FORM IS COMPLETE')
            </script>";
        exit();  

        move_uploaded_file($image_tmp, "../images/$image");

    }else{


        $sqli = "INSERT INTO posts (title, date, author, image, keywords, content) VALUES ('$title', ''$date , '$author', '$image', '$keywords', '$content')";
    }};
?>





<!doctype html>
<html>
    <head>
        <title>Inserting Data</title>
        <meta charset="utf-8">

    </head>

    <body>

        <form action="insert_data.php" id="InsertDataForm" method="post" enctype="multipart/form-data">
            <table width="600" align="center" border="10">
                <tr>
                    <td align="center" bgcolor="#CC6600" colspan="6"><h1>Insert New Data Here</h1></td>
                </tr>


                <tr>
                    <td align="right">Data Title</td>
                    <td><input style="width:300px;" type="text" name="title"/></td>
                </tr>


                <tr>
                    <td align="right">Data Author</td>
                    <td><input style="width:300px;" type="text" name="author"/></td>
                </tr>


                <tr>
                    <td align="right">Data Keywords</td>
                    <td><input style="width:300px;" type="text" name="keywords"/></td>
                </tr>


                <tr>
                    <td align="right">Data Image</td>
                    <td><input style="width:300px; height:50px;" type="file" name="image"/></td>
                </tr>


                <tr>
                    <td align="right">Data Content</td>
                    <td><textarea style="max-width:300px; max-height:300px;" name="content" cols="48" rows="20"></textarea></td>
                </tr>

                <tr>
                    <td align="center" colspan="6"><input style="width:200px; height:50px;
                    margin:5px 0px;" type="submit" name="submit" value="Insert Data Now"/></td>
                </tr>

            </table>
        </form>


    </body>
</html>

connection script

<?php
    $connect = mysqli_connect("localhost","########","####","#######");
?> 

no bad posts just HELP PLZ i dont want spelling correcting or negativity i want help.

regards and thanks in advance

  • 1
    To indent your code you have to highlight it and press `ctrl+k`. Please do that. – ZekeDroid May 19 '15 at 16:08
  • 1
    (to indent code in stack overflow press space 4 times instead of using tab) – monxas May 19 '15 at 16:08
  • 1
    *"no bad posts just HELP PLZ i dont want spelling correcting or negativity i want help."* - Irony never sleeps. – Funk Forty Niner May 19 '15 at 16:09
  • What do you see in the debugger when you run your code? – Yogi May 19 '15 at 16:17
  • 1
    a.) You're using HTML5 so you don't need to check to see if the inputs are blank as long as you use `required` in each input element. 2.) You never execute your input query. iii.) [Your script is at risk for SQL Injection.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). IV.) you're not following the most basic of guides for uploading files. FIVE.) You have syntax errors. Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard May 19 '15 at 17:03

1 Answers1

1

First make sure in your php.ini that file_uploads is uncommented.

file_uploads=On       instead of         ;file_uploads=On

Also you have an error in your INSERT. At the $date value.

You have

 ''$date     instead of      '$date'

Change to...

 $sqli = "INSERT INTO posts (title, date, author, image, keywords, content) VALUES ('$title', '$date' , '$author', '$image', '$keywords', '$content')";
Kylie
  • 11,421
  • 11
  • 47
  • 78