0

我想使用表单将多个图像添加到 mysql 数据库中。每当用户提交该表单时,它就会捕获所有数据并将其存储到 mysql 数据库中。(这是正确的方式,但我需要)

我的数据库表看起来像这样。

CREATE TABLE `Owner_detail` (
  `id` int(10) NOT NULL auto_increment,
  `fullname` varchar(30) NOT NULL,
  `List1` varchar(20) NOT NULL,
  `List2` varchar(20) NOT NULL,
  `List3` varchar(20) NOT NULL,
  `area` varchar(30) NOT NULL,
  `ownermobile` varchar(20) NOT NULL,
  `email` varchar(20) NOT NULL,
  `image_one` blob NOT NULL,
  `image_two` blob NOT NULL,
  `image_three` blob NOT NULL,
  `otherdetail` varchar(300) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=49 ;

我的 html 表单看起来像这样。

<table width="60%"><form action="process.php" method="post" enctype="multipart/form-data" name="tripleplay" onsubmit="MM_validateForm('fullname','','R','area','','R','ownermobile','','RisNum','email','','RisEmail','otherdetail','','R');return document.MM_returnValue">
  <tr>
    <td width="44%">Full Name : </td>
    <td width="56%"><input size="25" type="text" name="fullname" id="fullname" /></td>
  </tr>
  <tr>
    <td valign="top">Rental Type:</td>


    <td>

    <select name='List1' id="List1"     onchange="fillSelect(this.value,this.form['List2'])">
<option selected>Make a Selection</option>
</select>
<br /><br />
<select name='List2' id="List2" onchange="fillSelect(this.value,this.form['List3'])">
  <option selected>Make a Selection</option>
</select><br /><br />
<select name='List3' id="List3" onchange="getValue(this.value,     this.form['List2'].value, 
this.form['List1'].value)">
      <option selected>Make a Selection</option>
    </select>
</td>
  </tr>
  <tr>
    <td>Area : </td>
    <td><input size="25" type="text" name="area" id="area" />
  sq.ft.</td>
    </tr>
  <tr>
    <td>Owner Mobile / Landline</td>
    <td><input size="25" type="text" name="ownermobile" id="ownermobile" /></td>
  </tr>
  <tr>
    <td><p>E-mail</p></td>
    <td><input size="25" type="text" name="email" id="email" /></td>
  </tr>
  <tr>
    <td valign="top">Pictures of Property</td>
     <td>

       <input type="file" name="image_one" id="image_one" />


        <input type="file" name="image_two" id="image_two" />


        <input type="file" name="image_three" id="image_three" />
    </td>
  </tr>


  <tr>
    <td valign="top">Other details you would like to share about your property:</td>
    <td><textarea size="25" name="otherdetail" id="otherdetail" cols="45" rows="5">    </textarea></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
  </tr>
</form>
</table>

我在 php 中的处理形式是这样的

<?
if( $_POST )
{
  $con =     mysql_connect("","","");

  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("vkrental", $con);

  $users_fullname = $_POST['fullname'];
  $users_area = $_POST['area'];
  $users_List1 = $_POST['List1'];
  $users_List2 = $_POST['List2'];
  $users_List3 = $_POST['List3'];
  $users_ownermobile = $_POST['ownermobile'];
  $users_email = $_POST['email'];
  $users_image_one = $_POST['image_one'];
  $users_image_two = $_POST['image_two'];
  $users_image_three = $_POST['image_three'];
  $users_otherdetail = $_POST['otherdetail'];


  $users_fullname = htmlspecialchars($users_fullname);
  $users_area = htmlspecialchars($users_area);
  $users_List1 = htmlspecialchars($users_List1);
  $users_List2 = htmlspecialchars($users_List2);
  $users_List3 = htmlspecialchars($users_List3);
  $users_ownermobile = htmlspecialchars($users_ownermobile);
  $users_email = htmlspecialchars($users_email);
  $users_image_one = htmlspecialchars($users_image_one);
  $users_image_two = htmlspecialchars($users_image_two);
  $users_image_three = htmlspecialchars($users_image_three);
  $users_otherdetail = htmlspecialchars($users_otherdetail);




  $query = "
  INSERT INTO `vkrental`.`Owner_detail` (

`fullname` ,
`area` ,
`List1` ,
`List2` ,
`List3` ,

`ownermobile` ,
`email` ,
`image_one` ,
`image_two` ,
`image_three` ,
`otherdetail`
)
VALUES ( '$users_fullname',
        '$users_area', '$users_List1','$users_List2','$users_List3',     '$users_ownermobile', '$users_email',     '$users_image_one','$users_image_two','$users_image_three', '$users_otherdetail'
        );";

  mysql_query($query);

  echo "<h2>Success.</h2>";

   mysql_close($con);
}
 ?>

我的问题是当我从它成功存储的 mysql 数据库中插入图像时。但是当我从我的 html 表单中执行此操作时,它不会存储图像。它只存储数据(文本)。

我不知道我的表格中的实际错误是什么。

4

2 回答 2

0

我想知道使用htmlspecialchars()二进制数据会做什么。

$users_image_one = htmlspecialchars($users_image_one);
$users_image_two = htmlspecialchars($users_image_two);

[编辑:]

htmlspecialchars()用于保存文本数据的特殊字符。但是,如果您将它用于二进制数据,它会搞砸一切。

自己排除故障:

您可以尝试通过首先仅上传图像来找出问题。

也看看这个链接:文件上传使用POST方法

于 2013-06-15T10:49:58.610 回答
-1

听起来不像有错误。. . .

您不会将实际图像存储在数据库中,而只是存储它们的名称或对图像的引用

例如 product_one.jpg

然后当你想显示它时,你会做类似的事情

<img src=" <?php $echo \images\$users_image_one ?> ">
于 2013-06-15T10:46:16.760 回答