-1

我正在尝试通过 php 上传图像并将其存储在 mysql 数据库中。但没有图像存储在数据库中。

<form action="" method="get" name="frmPostImage" class="box" enctype="multipart/form-data">
    <table>
        <tr>
            <td><b>City:</b></td>
            <td>
                <select name="cityid">
                    <?php
                    $sql = "SELECT cityid, cityname, countryname
        FROM $t_cities ct
            INNER JOIN $t_countries c ON ct.countryid = c.countryid
        ORDER BY c.pos, ct.pos";
                    $res = mysql_query($sql) or die(mysql_error());

                    while($row=mysql_fetch_array($res))
                    {
                        echo "<option value=\"$row[cityid]\"";
                        if ($row['cityid'] == $_REQUEST['cityid']) echo " selected";
                        echo ">$row[countryname] > $row[cityname]</option>";
                    }

                    ?>
                </select>
            </td>
            </td>
        </tr>
        <tr>
        <tr>
            <td><b><?php echo $lang['POSTIMG_IMAGE_TITLE']; ?>:</b><span class="marker">*</span></td>
            <td><input name="imgtitle" type="text" id="imgtitle" size="55" maxlength="100" value="<?php echo isset($data

['imgtitle']); ?>"><br><img
                    src="images/spacer.gif"></td>
        </tr>

        <tr>
            <td><b><?php echo $lang['POSTIMG_IMAGE_FILE']; ?>:</b><span class="marker">*</span></td>
            <td><input name="img" type="file" size="45"><br><img src="images/spacer.gif"></td>
        </tr>

        <tr>
            <td><b><?php echo $lang['POSTIMG_IMAGE_DESCRIPTION']; ?>:</b></td>
            <td><textarea name="imgdesc" type="text" rows="5" cols="54"><?php echo $data['imgdesc']; ?></textarea><br><img 

src="images/spacer.gif"></td>
            <td> <input type="hidden" name="do" value="save"><button type="submit">Go</button></td>
        </tr>
    </table>

</form> 

并使用以下代码将其存储到数据库中。

$expiry = time()+($expire_images_after*24*60*60);
        $expiry_dt = date("Y-m-d H:i:s", $expiry);
        $city = $_REQUEST['cityid'];
    // Temporary file name stored on the server 
        $tmpName  = $_FILES['img']['tmp_name'];  

        $sql = "INSERT INTO $t_imgs
                SET imgtitle = '$_GET[imgtitle]',
                    imgfilename = '$tmpName',
                    imgdesc = '$_GET[imgdesc]',
                    postername = '$data[postername]',
                    cityid = '$city',
                    ip = '$ip',
                    verified = '1',
                    enabled = '1',
                    createdon = NOW(),
                    expireson = '$expiry_dt',
                    timestamp = NOW()"; 

         mysql_query($sql) or die($sql.mysql_error());

        if (mysql_affected_rows())
        {
            // Get ID
            $sql = "SELECT LAST_INSERT_ID() FROM $t_imgs";
            list($imgid) = mysql_fetch_array(mysql_query($sql));

        }
    }    

    ?>
<h2><?php echo $lang['POST_IMAGE_SUCCESS']; ?></h2>

我能够存储除图像之外的所有其他值。尝试了不同的组合,但没有任何效果。引导我...:)

4

1 回答 1

0

我认为 mysql 语句可能存在问题:而不是 $sql = "INSERT INTO $t_imgs SET imgtitle

您可能应该使用 $sql = "INSERT INTO $t_imgs values (imgtitle, ...);

在这里检查:http: //dev.mysql.com/doc/refman/5.5/en/insert.html

于 2013-05-05T09:00:00.287 回答