2012-10-18 36 views
0

我在網站上使用以下腳本,它完美地工作 - 在這裏詢問一個任務。我現在試圖把這個到另一個網站,它給我的錯誤Mysql錯誤:沒有數據庫選擇任何想法​​?你的幫助將非常感謝,我對這個東西很新。我知道腳本不是從安全角度來看最好 - 我正在研究這個!PHP MySQL文件上傳腳本不起作用

<?php 

require_once('../Connections/BrightLights.php'); 

//This is the directory where images will be saved 
$target = "images/"; 
$target = $target . basename($_FILES['photo']['name']); 

//This gets all the other information from the form 
$name=$_POST['name']; 
$caption=$_POST['caption']; 
$live=$_POST['live']; 
$photo=($_FILES['photo']['name']); 




//Writes the information to the database 
    mysql_query("INSERT INTO `gallery` VALUES ('', '$name', '$caption', '$photo', '$live')") ; 
    if(mysql_errno() != 0){ 
    // mysql error 
    // note: message like this should never appear to user, should be only stored in log 
    echo "Mysql error: " . htmlspecialchars(mysql_error()); 
    die(); 
} 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 
?> 
+0

嗯......你選擇的數據庫? – deceze

回答

0

「無選擇的數據庫」錯誤通常表現出來了,當你忘記帶mysql_select_db()選擇一個數據庫,並呼籲mysql_query()

+0

好的,感謝您的評論,我將如何將其實施到我的上述代碼中。我有相同的代碼在另一個網站上使用,它工作正常。 – AppleTattooGuy

+0

我需要看看'BrightLights.php'文件中的代碼,以檢查是什麼使它在一個站點上工作,而不是在另一個站點上。爲了使你當前的代碼能夠工作,你可以在require後加上'mysql_select_db('your_database_name');'。 – nebulousGirl

+0

非常感謝您的幫助,我添加了mysql_select_db('your_database_name');現在它完美地工作。 – AppleTattooGuy

0

之前ü查詢ü必須先連接,選擇數據庫的數據庫,那麼在哪裏查詢。使用此:

mysql_connect(hostname, username, password) or die(mysql_error()); 
mysql_select_db(database_name); 
+0

非常感謝您的幫助! :-) – AppleTattooGuy