1

挿入ではなく更新(UPDATEクエリを使用)してデータベースに画像を保存したい。

他のすべては正常に更新されますが、イメージは保存されません。画像を保存するために中規模の BLOB データ型を使用しています。

これが私のコードです:

update-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>

update-profile-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 から関連データのみをコピーして読みやすくしました :) どんな種類のヘルプも大歓迎です :)

4

1 に答える 1

1

2 つの問題:

ファイルの入力タグの ID がありません。<input type="file" name="image" value="" />に変更する必要があります<input type="file" name="image" value="" id = "profileimage" />

次に、経由$_POSTではなく経由でファイルにアクセスします$_FILES

于 2012-10-18T18:01:08.637 に答える