Jump to content

Recommended Posts

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 :P

 

Thanks everyone in advance, you guys are awesome!

 

EDIT: The live script is here

Edited by AureliusR
Link to comment
https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/
Share on other sites

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 by Manixat
Link to comment
https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422155
Share on other sites

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 by AureliusR
Link to comment
https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422163
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422166
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/276362-fresh-pair-of-eyes/#findComment-1422172
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.