douwang6635 2015-11-30 13:15
浏览 49

使用一个表单上传电子邮件和图像,使用PHP将路径和文本存储在数据库中

<form method="post"  enctype="multipart/form-data" action="saveimage.php">
    <table>
        <tr>
            <td width="250">Email: (will not be publicized)</td>
            <td>
                <input name="email" type="text" id="email" /><br />
            </td>
        </tr>
        <tr>
            <td width="250">Image</td>
            <td>
                <input name="image" type="file" id="file">
            </td>
        </tr>
        <tr>
            <td width="250"> </td>
            <td>
                <input name="add" type="submit" id="add" value="Order">
            </td>
        </tr>
    </table>
</form>

<?php
    if(isset($_POST['add'])) {
        $dbhost = 'localhost';
        $dbuser = 'iluxcoke_myuser';
        $dbpass = 'qwert';
        $db_name = 'inmoti6_mysite';
        $tbl_name = 'images_tbl';
        $ftp_user = 'admin@ilux.co.ke';
        $ftp_pass = 'qwert2012';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        if(! $conn ) {
            die('Could not connect: ' . mysql_error());
        }
        mysql_select_db("$db_name")or die("cannot select DB");
        $ftp_server = "ftp.ilux.co.ke";
        $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
        // login with username and password
        $login_result = ftp_login($ftp_conn, $ftp_user, $ftp_pass);
        // check connection
        if ((!$ftp_conn) || (!$login_result)) {
            echo "FTP connection has failed!";
            echo "Attempted to connect to $ftp_server for user $ftp_user";
            exit;
        } else {
            echo "Connected to $ftp_server, for user $ftp_user";
        }
        $Email = $_POST['email'];
        $filePath="http://www.iluxcoke/public_html/admin" . $_FILES["file"]["name"];
        // $Type = $_POST['type'];
        if ($_FILES["file"]["error"] > 0) {
            echo "Error: NO CHOSEN FILE <br />";
            echo"INSERT TO DATABASE FAILED";
        } else {
            move_uploaded_file($_FILES["file"]["tmp_name"], __DIR__ . "/upload/" . $_FILES["file"]["name"]);
            echo"SAVED<br>";
            $sql = "INSERT INTO `images_tbl` ( `id`, `email`, `image`, `submission_date`) VALUES ('$id','$Email','$filePath', curdate())";
            if(mysql_query($query_image)) {
                echo "Stored in: " . "uploads" . $_FILES["file"]["name"];
            } else {
                echo 'File name not stored in database';
            }
        }
    }
?>

I'm trying to allow the user to input an email and an image and upload it to my website admin folder but I'm having issues and it displays this error:

Connected to ftp.ilux.co.ke, for user admin@ilux.co.keSAVED
    File name not stored in database
  • 写回答

1条回答 默认 最新

  • dqroc48068 2015-11-30 13:32
    关注

    I think you're using the wrong SQL string in the mysql_query() function. You're using $query_image, and your query is defined in the $sql variable.

    Try this instead:

    //HERE IS THE CHANGE
    if(mysql_query($sql))
    //------------------
    {
    echo "Stored in: " . "uploads" . $_FILES["file"]["name"];
    }
    else
    {
     echo 'File name not stored in database';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败