如何通过单击图像本身来存储图像文件路径

时间:2019-04-09 16:44:07

标签: php html mysql

我试图允许用户从一组简单的4个头像中进行选择,并将其用作个人资料图片。

我尝试使用:

<input type="image" class="profile-image-icon" src="img/avatar/avatar1.png" name="image" id="image">

但是我最终发现使用input type="image"仅用于将图像用作提交按钮。

有问题的头像已经在我的img/avatar文件夹中,然后我只想将图像路径存储在数据库中。

我已经在changeProfile.php上回显了任何错误消息,该错误消息返回“ Nothing through through”,所以我知道这是我的表单存在的问题,但是我不确定如何继续。

无论如何,是否存在允许用户简单地单击图像并将其“ POSTS”到changeProfile.php的地方,然后我可以在其中检索要存储在数据库中的文件路径?

感谢您提供的任何帮助!

edit_profile_image.php

<form class="profile-image-form" method="POST" action="profileChanged.php">                       

<fieldset>
<div class="image-control">
<input type="image" class="profile-image-icon"src="img/avatar/avatar1.png" name="image" id="image">
</div>
<?php echo "<input type='text' class='form-control' id='studentNumber' name='studentNumber'  value='$studentID'>"; ?>  
</fieldset>                      

</form> 

changeProfile.php


if (isset($_POST['image'])) {

$image = mysqli_real_escape_string($conn, $_POST['image']);
$studentNumber = mysqli_real_escape_string($conn, $_POST['studentNumber']);

} else {
    echo "Nothing coming thorugh";
}

0 个答案:

没有答案