2013-09-27 64 views
-2

我正在學習PHP和phpMyAdmin的我要上傳圖片到數據庫,然後回顯到另一個頁面相同的圖像的任何一個可以幫助我如何上傳圖片並將同一圖片回顯到另一頁...?

的index.html

<html> 
<body> 
    <form name="form" method="post" action="insert_ac.php"> 
     <h1>Insert Data Into mySQL Database</h1> 

      name...... <input name="name" type="text" id="name"> <br><br> 
      username.... <input name="username" type="text" id="username"> <br><br> 
      password.. <input name="password" type="text" id="lastname"><br><br> 
      Email..... <input name="email" type="text" id="email"><br><br> 
      Upload Image....... :<input type="file" name="image" id="uploadimg"><br> 
     <input type="submit" name="Submit" value="Submit"> 
    </form> 
</body> 
</html> 

insert_ac.php

<?php 

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="loginfour"; // Database name 
$tbl_name="test_four"; // Table name 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

// Get values from form 
$username=$_POST['username']; 
$password=$_POST['password']; 
$email=$_POST['email']; 
$name=$_POST['name']; 

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(username, password, email, name)VALUES('$username', '$password', '$email', '$name')"; 
$result=mysql_query($sql); 

// if successfully insert data into database, displays message "Successful". 
if($result){ 
echo "Successful"; 
echo "<BR>"; 
echo "<a href='insert.php'>Back to main page</a>"; 
} 

else { 
echo "ERROR"; 
} 
?> 

<?php 
// close connection 
mysql_close(); 
?> 

我想上傳圖片並將其顯示給insert_ac.php任何一個人協助我..........................

+0

看一看http://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/ –

+0

很多的教程退出互聯網,嘗試谷歌搜索,插入您的圖像名稱img.jpg數據庫和上傳文件到您的文件夾,然後concat路徑名稱 –

+0

有兩種模式用於存儲數據庫中的圖像。首先是僅存儲映像文件的路徑,並將文件本身存儲在文件系統中。秒是將實際圖像作爲blob存儲在數據庫中。 PS:不要使用'mysql'庫,在使用php-mysql時請使用'mysqli'。 –

回答

0

php頁面很簡單

echo($_FILES["image"]["name"]); 

reference

+0

我只是在你的答案中指出了一個小錯字 - 感謝你糾正錯誤! – andrewsi

+0

@andrewsi解釋的方式很棒,thnx – 2013-09-27 13:46:05

相關問題