hane Posted September 22, 2009 Share Posted September 22, 2009 Hi I need some help please I got an image upload code that loads the image to the folder and stores the filename in a mysql database. Now it works 100% when I run the code locally with XAMPP but it doesnt update the record in mysql when I do it on my webserver. Here is my action code: <?php $uploadDir = '../excaload/foto/'; $id=$_POST["id"]; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } $con = mysql_connect("xxxxxxx","xxxxxxx","xxxxxx"); if (!$con) { die('Error connecting to database'); } mysql_select_db("xxxxx", $con); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } mysql_query("UPDATE c_listing SET image ='" . "$fileName" . "' WHERE c_listing_id ='" . "$id" . "' "); mysql_close($con); echo "<img src='../excaload/foto/" . "$fileName" . "' alt='' width='300'/>"; } ?> I just need someone else to look at the code because I've been going through it over and over and I'm missing it. All the rest of my insert and update statements on the website work. Thanks for having a look Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/ Share on other sites More sharing options...
dennismonsewicz Posted September 22, 2009 Share Posted September 22, 2009 it could be possible that you don't have 777 permissions on that folder you are moving the files into Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922747 Share on other sites More sharing options...
dennismonsewicz Posted September 22, 2009 Share Posted September 22, 2009 if that is the case take a look here: http://us2.php.net/manual/en/function.chmod.php Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922748 Share on other sites More sharing options...
hane Posted September 22, 2009 Author Share Posted September 22, 2009 the file gets loaded, the name just isn't being written to the database Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922752 Share on other sites More sharing options...
dennismonsewicz Posted September 22, 2009 Share Posted September 22, 2009 change mysql_query("UPDATE c_listing SET image ='" . "$fileName" . "' WHERE c_listing_id ='" . "$id" . "' "); to mysql_query("UPDATE c_listing SET image ='$fileName' WHERE c_listing_id ='$id' "); Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922753 Share on other sites More sharing options...
hane Posted September 22, 2009 Author Share Posted September 22, 2009 Nope not working Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922756 Share on other sites More sharing options...
dennismonsewicz Posted September 22, 2009 Share Posted September 22, 2009 print_r($fileName) and make sure there is something there. Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922758 Share on other sites More sharing options...
hane Posted September 22, 2009 Author Share Posted September 22, 2009 the file name must be there because after the upload it must show me the image by using the $filename and it does. And also it works on my local host Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922761 Share on other sites More sharing options...
dennismonsewicz Posted September 22, 2009 Share Posted September 22, 2009 change ur mysql statement to: mysql_query("UPDATE c_listing SET image ='" . "$fileName" . "' WHERE c_listing_id ='" . "$id" . "' ")or trigger_error(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922763 Share on other sites More sharing options...
hane Posted September 22, 2009 Author Share Posted September 22, 2009 It doenst upload the filename to the database and it doesnt give me an error Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922765 Share on other sites More sharing options...
hane Posted September 22, 2009 Author Share Posted September 22, 2009 I got it, thanks for your help. The $id wat empty as I wasnt posting it from my form. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/175081-solved-code-working-on-local-host-but-not-on-server/#findComment-922767 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.