1

i am new in php... i had created a simple php file upload script given below...

form.php

<form action="uploader.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<input type="submit" name="submit" value="Submit" />
</form>

uploader.php

<?php
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
?>

my question is i had created a mysql database account and a table student with 4 field id, name, age, image i want store my uploaded image path to these table, and display this image my web page where i want... have any simple solutions.? with example... sorry im just new in mysql

thanks....

4

1 回答 1

0

我假设您的数据库中已经有学生并更改了他们的个人资料图片

用户必须登录才能上传图片,因此您将使用类似 $_SESSION['studentid'] 的内容

<?php
$path = "upload/" . $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],$path);

$sql = "UPDATE students SET image = '".$path."' WHERE id = ".$_SESSION['studentid'];
mysql_query($sql) OR die(mysql_error());

?>

稍后,如果您想显示用户图像,请使用此查询

<?php

$sql = "SELECT image FROM students WHERE id = ".$_SESSION['studentid'];
$result = mysql_query($sql) OR die(mysql_error());
$row = mysql_fetch_assoc($result);

echo $row['image'];
?>
于 2012-11-19T16:07:16.513 回答