fife Posted December 23, 2010 Share Posted December 23, 2010 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.""); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/222493-image-uploader/ Share on other sites More sharing options...
the182guy Posted December 23, 2010 Share Posted December 23, 2010 The database username and/or password is incorrect. Check your webhost control panel for the correct credentials. Quote Link to comment https://forums.phpfreaks.com/topic/222493-image-uploader/#findComment-1150755 Share on other sites More sharing options...
PFMaBiSmAd Posted December 23, 2010 Share Posted December 23, 2010 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?) Quote Link to comment https://forums.phpfreaks.com/topic/222493-image-uploader/#findComment-1150760 Share on other sites More sharing options...
fife Posted December 24, 2010 Author Share Posted December 24, 2010 yes I thought of both of these issues but..... The the include('photoconnect.php') is correct. The code is exactly the same as on another page with the same include in the same folder. I just dont understand whats wrong. Quote Link to comment https://forums.phpfreaks.com/topic/222493-image-uploader/#findComment-1150974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.