【问题标题】:Updating image into databse using php and mysql使用 php 和 mysql 将图像更新到数据库中
【发布时间】:2012-10-09 06:28:36
【问题描述】:

我想通过更新(通过使用 UPDATE 查询)而不是插入来将图像存储在数据库中。

其他所有内容均已成功更新,但未存储图像。我正在使用中等 blob 数据类型来存储图像。

这是我的代码:

更新-profile.php:

  <form id="form" method="post" action="update-profile-action.php"   enctype="multipart/form-data">
    <label for="Fname">First Name:</label> <input type="text" id="Fname" class="text"  value="<?php echo $firstname; ?>" name="Fname" /> <br /><br />
     <label for="Lname">Last Name:</label> <input type="text" id="Lname" class="text"    value="<?php echo $lastname; ?>" name="Lname" /><br /> <br />

<?php 
if ($_SESSION["type"]=="T")
{
?>        
    <label>Profile Image:</label> <input type="file" name="image" value="" /><br     />     <br />
     <label>Qualification:</label><textarea name="qualification" class="text"  id="qualification"><?php echo $qualification;?></textarea><br /><br />
    <label>Education & Teaching History:</label> <textarea name="briefintro"     class="text" id="intro"><?php echo $briefintro; ?></textarea><br /><br />
<?php
}
?>
    <input type="submit" class="mybutton" value="Update Profile" />

</form>

更新配置文件action.php:

<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$image=$_POST["profileimg"];
$briefintro=$_POST["briefintro"];
$qualification=$_POST["qualification"];

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' ,  profileimg='".$image."' ,  briefintro='".$briefintro."',    qualification='".$qualification."' WHERE id=".$_SESSION['id']);
$result = mysql_query($query);
header("Location: update-profile.php?status=3");
mysql_close($con);
?>

我只复制了 update-profile.php 中的相关数据以使其更易于阅读:) 任何形式的帮助将不胜感激:)

【问题讨论】:

  • 我没有看到 "$_POST["profileimg"];"在您的 html 表单中。其次,您不要使用 $_POST 访问上传的文件,而是使用 $_FILES 全局数组
  • 另外,明智的说法是,不要将图像存储在数据库中,而是处理上传,将文件移动到您计划在服务器上存储的位置,然后存储图像的路径在数据库中。

标签: php mysql html css


【解决方案1】:

两个问题:

您没有文件输入标签的 id。你需要把&lt;input type="file" name="image" value="" /&gt;改成&lt;input type="file" name="image" value="" id = "profileimage" /&gt;

其次,您不是通过$_POST 而是通过$_FILES 访问文件。

【讨论】:

    猜你喜欢
    • 2019-09-11
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 2014-01-04
    • 1970-01-01
    相关资源
    最近更新 更多