0

我在一个网站上使用以下脚本,它运行良好 - 在此处询问后。我现在试图把它放到另一个站点,它给了我错误 Mysql error: No database selected any ideas? 非常感谢您的帮助我对这些东西很陌生。从安全的角度来看,我知道脚本并不是最好的——我正在努力解决这个问题!

<?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."; 
 } 
 ?> 
4

2 回答 2

0

在您查询数据库之前,您必须先连接并选择数据库,然后您才能查询它。用这个:

mysql_connect(hostname, username, password) or die(mysql_error());
mysql_select_db(database_name);
于 2012-10-18T14:56:57.967 回答
0

当您忘记选择数据库mysql_select_db()并调用时,通常会出现“未选择数据库”错误mysql_query()

于 2012-10-18T14:57:18.530 回答