2012-10-18 38 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