【问题标题】:My files and information will not upload (mysqli & PHP)我的文件和信息不会上传(mysqli & PHP)
【发布时间】:2015-05-19 16:06:54
【问题描述】:

您好,我已经构建了一个上传器,可以上传一些数据和一张图片。

表单在网页上显示没有错误但不会上传。

这是一个屏幕截图,也附上了代码。

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>

连接脚本

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

没有不好的帖子,只是帮助 PLZ,我不想拼写更正或消极,我需要帮助。

提前致谢

【问题讨论】:

  • 要缩进您的代码,您必须突出显示它并按ctrl+k。请这样做。
  • (将堆栈溢出的代码缩进 4 次而不是使用制表符)
  • “没有不好的帖子,只是帮助 PLZ,我不想拼写更正或消极,我需要帮助。” - 讽刺从不睡觉。
  • 运行代码时在调试器中看到了什么?
  • a.) 您使用的是 HTML5,因此只要您在每个输入元素中使用 required,就无需检查输入是否为空白。 2.) 你永远不会执行你的输入查询。 iii.) Your script is at risk for SQL Injection.。 IV.)您没有遵循上传文件的最基本指南。五)你有语法错误。在您打开 &lt;?php 标记 error_reporting(E_ALL); ini_set('display_errors', 1); 后立即在文件顶部添加错误报告

标签: javascript php jquery html css


【解决方案1】:

首先确保在您的 php.ini 中取消注释 file_uploads。

file_uploads=On       instead of         ;file_uploads=On

您的 INSERT 也有错误。在 $date 值。

你有

 ''$date     instead of      '$date'

更改为...

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

【讨论】:

  • 谢谢,我会在大约一个小时后尝试,如果可行,请更新:)
猜你喜欢
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-20
相关资源
最近更新 更多