Jump to content

image uploader


fife

Recommended Posts

Hi I have this script which I hope to upload an image to my images folder and put the name of the image in my database along with what category it belongs too.  I keep getting this error though....

 

Access denied for user 'websitename.co.uk'@'localhost' (using password: NO)

 

Now when I check the server logs I get the following error to go with it...

 

[Thu Dec 23 13:53:30 2010] [error] [client 0.0.0.0] PHP Warning:  mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in /home/sites/website name.co.uk/public_html/manage/upload.php on line 14, referer: http://www.websitename.co.uk/manage/add_image.php?cat='Robbers'

 

Lie 14 is this...

 mysql_query("INSERT INTO `polaroids` VALUES ('$pic', '$category')")  or die (mysql_error());  

 

Ok so here is the code from the beginning.  Ill start with the form its self....

<form enctype="multipart/form-data" action="upload.php" id="polaroidfrm" method="POST">
Please upload a PNG for the category <?php echo $_GET['cat']; ?>:<br>
<input name="photo" type="file"  size="40"/>
</p>
<br/>
<input type="hidden" name="category" Value="<?php echo $_GET['cat']; ?>">
<input type="submit" value="Submit" name="insert_polaroid">
</form>

 

then the upload page....

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

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

// Connects to your Database 
include('../../Connections/photoconnect.php'); 
session_start();
//Writes the information to the database 
mysql_query("INSERT INTO `polaroids` VALUES ('$pic', '$category')")  or die (mysql_error());  

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 
//Tells you if its all ok 
$success =  "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
$url = "polaroids.php?polaroidpass='".$success."'" or die(mysql_error());        
header("Location: ".$url.""); 
} 

else { 

//Gives and error if its not 
$fail =  "Sorry, there was a problem uploading your file."; 
   $url = "polaroids.php?polaroidfail='".$fail."'" or die(mysql_error());        
header("Location: ".$url."");
} 
?> 

 

 

Link to comment
https://forums.phpfreaks.com/topic/222493-image-uploader/
Share on other sites

If your mysql_query() statement attempted to created a database connection, it means that your actual connection code either was not executed or failed to make a connection.

 

Either your include() statement failed because the path or the file name is wrong, your code in photoconnect.php was not seen as being php code (using short open tags <? or has not php tags at all), or the mysql_connect() statement in photoconnect.php failed (do you have any error checking logic in your photoconnect.php code to even test if the connection worked?)

Link to comment
https://forums.phpfreaks.com/topic/222493-image-uploader/#findComment-1150760
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.