AureliusR Posted March 31, 2013 Share Posted March 31, 2013 (edited) So I've been grinding on this for hours and as I'm just learning, it's not clear to me what's wrong. I just cannot figure out what's not working. Maybe a fresh pair of eyes and a clear head will spot it. The form is supposed to submit a name, score and screenshot to 'prove' the score in a fictional game Guitar Wars. The user enters their name and score, then chooses a screenshot file (I've been using .gifs and .jpgs to test it) and then clicks add. The form is supposed to enter that info into the database, then move the image file from it's temporary spot to the /images directory of this php script. Seems simple, right? Well I can't for the life of me figure out what's wrong. When I click add the filename disappears and the form does nothing, but the name and score stay entered -- which tells me it's not getting to the end of the main if, where it clears the form data. No communcation happens with the SQL server, I've checked the logs. Here's a paste of what I have. Once again I feel like it's going to be some simple newbie mistake and I'll feel like a fool for asking here, but if I don't ask I'll go crazy Thanks everyone in advance, you guys are awesome! EDIT: The live script is here Edited March 31, 2013 by AureliusR Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/ Share on other sites More sharing options...
Manixat Posted March 31, 2013 Share Posted March 31, 2013 (edited) No communcation happens with the SQL server, Well you said it. Echo mysql_error() at the end and see what you get. Also, never trust the user, escape any input, even if it's not meant to be edited ( like select nodes and such ). See mysqli_real_escape_string() Edited March 31, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422155 Share on other sites More sharing options...
AureliusR Posted March 31, 2013 Author Share Posted March 31, 2013 mysql_error() is returning nothing... I'm pretty sure the problem is happening before any communication with the MySQL server, so mysql_error won't help. And by escape, do you mean add \ before any text box entries? Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422158 Share on other sites More sharing options...
Manixat Posted March 31, 2013 Share Posted March 31, 2013 You're missing a slash in here: define('GW_UPLOADPATH', '/guitars/images'); $screenshot = $_FILES['screenshot']['name']; $target = GW_UPLOADPATH . $screenshot; $target becomes '/guitars/imagesScreenshot.jpg' instead of '/guitars/images/Screenshot.jpg' Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422159 Share on other sites More sharing options...
AureliusR Posted March 31, 2013 Author Share Posted March 31, 2013 (edited) Yeah, I just caught that after reading apache's error.log and I fixed it, and it's still not working. EDIT: I also tried './images/guitars/' as well as '/images/guitars/ .. Edited March 31, 2013 by AureliusR Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422161 Share on other sites More sharing options...
AureliusR Posted March 31, 2013 Author Share Posted March 31, 2013 (edited) Oh, I may have fixed it... I changed the path to explicitly be /var/www/guitars/images and then I did chmod 777 /var/www/guitars/images and it seems to be working... except the images don't show up yet. And that seems to be broken too... if I set the path to be /var/www/guitars/images, when it goes to load the image later it of course adds that whole path so it won't display it. But if I don't put the whole path it tries to move it to the wrong directory... Edited March 31, 2013 by AureliusR Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422163 Share on other sites More sharing options...
Manixat Posted March 31, 2013 Share Posted March 31, 2013 (edited) Well your code seems fine to me. Notice that neither the then nor the else bolck are firing in your 'live script' -> if (!empty($name) && !empty($score) && !empty($screenshot)) { Edited March 31, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422164 Share on other sites More sharing options...
AureliusR Posted March 31, 2013 Author Share Posted March 31, 2013 Well your code seems fine to me. Notice that neither the then nor the else bolck are firing in your 'live script' -> if (!empty($name) && !empty($score) && !empty($screenshot)) { I don't understand when you mean. Why would it not fire? If the submit button is pressed, and all three fields have data, what would be stopping it? When I look in the access and error logs for apache it keeps saying move_uploaded_file: cannot move /tmp/php46zfga7 to /var/www/guitars/images/whatever.jpg ... but the permissions for that folder are universal. I'm stumped. Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422166 Share on other sites More sharing options...
Manixat Posted March 31, 2013 Share Posted March 31, 2013 Are you sure that the images folder exists ? move_uploaded_file cannot create folders Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422168 Share on other sites More sharing options...
AureliusR Posted March 31, 2013 Author Share Posted March 31, 2013 Yeah, I'm sure. The strange thing is, when I look in the images folder, the first image I tried to upload after I fixed the slash and the permission is there... but it didn't show up in the confirmation part of the script after upload. Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422171 Share on other sites More sharing options...
Manixat Posted March 31, 2013 Share Posted March 31, 2013 Okay look, try uploading another image, see if it gets uploaded. If it does but the code is still giving you a hard time, then probably there's something wrong with your mysql stuff which you can determine really easily by mysqli_error(). If not then you still need to figure why move_uploaded_file is giving you such a hard time. I have to go now, I hope I've been of any assistance and good luck! Quote Link to comment https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422172 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.