我上傳我的圖片到數據庫,但點擊上傳按鈕後,它沒有上傳到數據庫,它只是刷新,當我手動添加圖片到數據庫中它進入我的數據庫網站,這裏是我的照片點擊上傳按鈕到數據庫後我的圖像沒有上傳
這裏是源代碼,上傳圖片:
<?php
include('lock.php');
mysqli_connect("localhost", "root", "Bhawanku", "members");
if(isset($_POST['emp_name'])){
$content=file_get_contents($_FILES['pic']['tmp_name']);
@list(, , $imtype,) = getimagesize($_FILES['pic']['tmp_name']);
if ($imtype == 3){
$ext="png";
}elseif ($imtype == 2){
$ext="jpeg";
}elseif ($imtype == 1){
$ext="gif";
}
$q="insert into employees set empname='".$_POST['emp_name']."',profile_pic='".$content."',ext='".$ext."'";
mysql_query($q);
header("location: getting_started.php");
}
?>
<html>
<head>
<title>Getting started..</title>
</head>
<style>
body{
background-color: #993333;
}
#box{
-webkit-box-shadow: 0px 0px 10px 0px rgba(110, 48, 50, 0.75);
-moz-box-shadow: 0px 0px 10px 0px rgba(110, 48, 50, 0.75);
box-shadow: 0px 0px 10px 0px rgba(110, 48, 50, 0.75);
background-color: #F0F0F0;
position: fixed;
width: 70%;
left: 18%;
top: 8%;
height: 70%;
}
#user_pic{
position: absolute;
top: 18%;
left: 12%;
}
h1{
position: fixed;
left: 19%;
font-family: Throw My Hands Up in the Air;
}
#btn_pos{
position: absolute;
left: 45%;
top: 38%;
}
#next_btn{
border:1px solid #2a2c2f; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 7px 30px 8px 30px; text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
background-color: #45484d; background-image: -webkit-gradient(linear, left top, left bottom, from(#45484d), to(#000000));
background-image: -webkit-linear-gradient(top, #45484d, #000000);
background-image: -moz-linear-gradient(top, #45484d, #000000);
background-image: -ms-linear-gradient(top, #45484d, #000000);
background-image: -o-linear-gradient(top, #45484d, #000000);
background-image: linear-gradient(to bottom, #45484d, #000000);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#45484d, endColorstr=#000000);
margin: 140px 0px 0px 220px;
cursor: pointer;
}
#btn_upload{
border:1px solid #2a2c2f; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 7px 30px 10px 30px; text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
background-color: #45484d; background-image: -webkit-gradient(linear, left top, left bottom, from(#45484d), to(#000000));
background-image: -webkit-linear-gradient(top, #45484d, #000000);
background-image: -moz-linear-gradient(top, #45484d, #000000);
background-image: -ms-linear-gradient(top, #45484d, #000000);
background-image: -o-linear-gradient(top, #45484d, #000000);
background-image: linear-gradient(to bottom, #45484d, #000000);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#45484d, endColorstr=#000000);
margin: 10px 0px 0px 0px;
cursor: pointer;
}
#img_pos{
position: fixed;
top: 20%;
left: 22%;
width: 25%;
height: 30%;
}
</style>
<body>
<div id="box">
<h1>Add your profile pic to look better ;)</h1>
<?php
$q="select * from employees";
$resultset=mysql_query($q);
if(mysql_num_rows($resultset)==0){
?>
<div id="user_pic">
<img id="img_pos" src="Images/default_user.png" >
</div>
<?php
}
while($rec=mysql_fetch_array($resultset)){
?>
<img id="img_pos" src="load_image.php?pic_id=<?php echo $rec['id'];?>" >
<?php
}
?>
<div id="btn_pos">
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="pic"><br>
<button id="btn_upload" type="submit">Upload now..</button>
</form>
<form>
<button id="next_btn" type="submit" name="next">Next</button>
</form>
</div>
</div>
</body>
</html>
,這裏是數據庫的源代碼:
<?php
mysql_connect("localhost","root", "Bhawanku");
mysql_select_db("members");
$q="select * from employees where id=".$_GET['pic_id'];
$rec=mysql_fetch_array(mysql_query($q));
$data=$rec['profile_pic'];
header('Content-Length: '.strlen($data));
header("Content-type: image/".$rec['ext']);
echo $data;
編輯: -
您好,我發現我的問題是因爲我沒有使用這個
<input type="text" name="emp_name" />
,我刪除了我的代碼,這導致,它根本不會救我的照片進入數據庫,因爲這個代碼,如果我使用它,它會更新我的圖片,所以你可以告訴我沒有被用於我的代碼和圖片將能夠上傳到數據庫請幫助:(因爲所有我的問題是由於這個原因造成的。
* mysqli *和* mysql * extensions的混合使用。選擇一個(提示,這是**不** * * mysql *) – Phil
會告訴我我做錯了什麼? – user3309991
在您的第一個代碼示例中,您使用'mysqli_connect'連接到數據庫(但不要將返回值設置爲任何內容),然後繼續使用'mysql_query'。兩者不兼容。 – Phil