I am using the following script on a site and it works perfectly – following asking a questing on here. I have now tried to put this into another site and it is giving me the error Mysql error: No database selected any ideas? your help would be really appreciated I am quite new to this stuff. I know the script isn’t the best from a security stand point – I am working on this!
<?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.";
}
?>
The “No database selected” error typically shows itself when you forgot to select a database with
mysql_select_db()and calledmysql_query()