Jump to content

saireuh

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by saireuh

  1. Yeah the book isn't too bad... not overly simple, it's just that when a problem occurs they tend to leave the bits out that help explain why.
  2. O'Reilly's Head First PHP & MySQL. It's a uniquely written book and it's a very easy read... but I've come across a few places where the errors (or unmentioned steps/problems in a tutorial) really hold me up.
  3. Oh my goodness! FINALLY! It's working! Thank you SO SO much for suggesting the mod rewrite.. that was creating the problem. After I changed the file permissions on the image folder at the new place I'm hosting it at, it worked! You have no idea how much aggravation this caused me. It was in a tutorial book for Pete's sake, it should have been easier than this.
  4. Okay... I added the site to a different server with no php previously on it... no mod re-writes or anything. www.allhinges.com/sara/PHP6/index.php Now the images are displayed there BUT when I attempt to upload an image I get this error: array(1) { ["screenshot"]=> array(5) { ["name"]=> string(15) "nevilsscore.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(14) "/tmp/phpsArkp1" ["error"]=> int(0) ["size"]=> int(12214) } } array(4) { ["MAX_FILE_SIZE"]=> string(5) "32768" ["name"]=> string(6) "Sara H" ["score"]=> string( "99999999" ["submit"]=> string(3) "Add" } pass1 pass2 pass3 Warning: move_uploaded_file(images/nevilsscore.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/hinges/public_html/sara/PHP6/addscore.php on line 38 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpsArkp1' to 'images/nevilsscore.gif' in /home/hinges/public_html/sara/PHP6/addscore.php on line 38 Sorry, there was a problem uploading your screen shot image.
  5. Grr well... no dice if it's set at 755 OR 777.... The mod re-write wouldn't affect permissions? I'm not quite sure if there is any way to find the right permissions setting...
  6. Okay I changed the permissions 755. To be honest the main site, gamerecoil, is using mod-rewrites but I'm not sure if that could affect my folder? I guess its possible. Is there anything I could do? If not I could try to host my folder somewhere else.
  7. The error I was receiving, as if I already submitted the script, was fixed. So that's no longer displayed when I first load addscore.php... After adding the checkpts I got this: array(1) { ["screenshot"]=> array(5) { ["name"]=> string(15) "nevilsscore.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(14) "/tmp/phpWKXcWx" ["error"]=> int(0) ["size"]=> int(12214) } } array(4) { ["MAX_FILE_SIZE"]=> string(5) "32768" ["name"]=> string(5) "Saire" ["score"]=> string(7) "9394999" ["submit"]=> string(3) "Add" } pass1 pass2 pass3 pass4 So I'm assuming everything is acting as it should? But I can't find the tmp folder, the img files... I set all of the file permissions to 777 and I'm realizing that the images ARE being moved to the image/ folder.. but index. php cannot display it!!! www.gamerecoil.com/Sara/PHP6/addscore.php www.gamerecoil.com/Sara/PHP6/index.php
  8. (By the way, thanks so much for helping ) After adding that I got: array(1) { ["screenshot"]=> array(5) { ["name"]=> string(15) "kennysscore.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(14) "/tmp/phpQaj7a8" ["error"]=> int(0) ["size"]=> int(12434) } } array(4) { ["MAX_FILE_SIZE"]=> string(5) "32768" ["name"]=> string(11) "Scotty Ryan" ["score"]=> string( "99999999" ["submit"]=> string(3) "Add" }
  9. Hmm okay I got this after attempting to submit a file with the var_dump($_FILES): array(1) { ["screenshot"]=> array(5) { ["name"]=> string(15) "nevilsscore.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(14) "/tmp/phpWV5BW4" ["error"]=> int(0) ["size"]=> int(12214) } } I'm unsure why the !empty($screenshot) would be the problem part... I thought that this is saying basically if there is a screenshot that is uploaded, move it to the images folder? Among other things?
  10. Okay within the past few minutes I was able to stop the error messages when I attempt to submit a high score (looking at the provided 'final' version of the code, which it itself has errors)... BUT... On addscore.php when I load it for the first time, I get the error message "Please enter all of the information to add your high score." as if it already checked for info to be in the fields? Would this have to do with a problem with the 'if (isset($_POST['submit'])' part of the code? And then the error that occurs on index.php... when the file is uploaded .. I cannot find it's 'tmp' folder and index.php is not displaying any image at all. So my attempt to move the img from tmp folder to the image folder is apparently failing...
  11. Hey everyone! I've been trying to teach myself php & mysql stuff and to do so I've done some online tutorials and bought a couple books to help me along. I'm so lost with these 2 php files... it has to do with uploading high scores and images to a database (and then moving those images from tmp file to a permanent location). I was thinking that maybe this was a permissions problem or maybe just a tiny error in the code that I'm not catching... When I go to the addscore.php to upload it will give me an error message and then on index.php NONE of the images are displayed. (there are a couple other .phps associated with these two but they are the main ones that I'm concerned about.) Would any of you guys have an idea? Please help! addscore.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guitar Wars - Add Your High Score</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Guitar Wars - Add Your High Score</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_POST['submit'])) { // Grab the score data from the POST $name = $_POST['name']; $score = $_POST['score']; $screenshot = $_FILES['screenshot']['name']; $screenshot_type = $_FILES['screenshot']['type']; $screenshot_size = $_FILES['screenshot']['size']; if (!empty($name) && !empty($score) && !empty($screenshot)) { if ((($screenshot_type == 'image/gif') || ($screenshot_type == 'image/jpeg') || ($screenshot_type == 'image/pjpeg') || ($screenshot_type == 'image/png')) && ($screenshot_size > 0) && ($screenshot_size <= GW_MAXFILESIZE)) { if ($_FILES['screenshot']['error'] == 0) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $screenshot; if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Write the data to the database $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score', '$screenshot')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for adding your new high score! It will be reviewed and added to the high score list as soon as possible.</p>'; echo '<p><strong>Name:</strong> ' . $name . '<br />'; echo '<strong>Score:</strong> ' . $score . '<br />'; echo '<img src="' . GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>'; echo '<p><a href="index.php"><< Back to high scores</a></p>'; // Clear the score data to clear the form $name = ""; $score = ""; $screenshot = ""; mysqli_close($dbc); } else { echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>'; } } } else { echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>'; } // Try to delete the temporary screen shot image file @unlink($_FILES['screenshot']['tmp_name']); } else { echo '<p class="error">Please enter all of the information to add your high score.</p>'; } } ?> <hr /> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="score">Score:</label> <input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" /><br /> <label for="screenshot">Screen shot:</label> <input type="file" id="screenshot" name="screenshot" /> <hr /> <input type="submit" value="Add" name="submit" /> </form> </body> </html> and index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guitar Wars - High Scores</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Guitar Wars - High Scores</h2> <p>Welcome, Guitar Warrior, do you have what it takes to crack the high score list? If so, just <a href="addscore.php">add your own score</a>.</p> <hr /> <?php require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the score data from MySQL $query = "SELECT * FROM guitarwars ORDER BY score DESC, date ASC"; $data = mysqli_query($dbc, $query); // Loop through the array of score data, formatting it as HTML echo '<table>'; $i = 0; while ($row = mysqli_fetch_array($data)) { // Display the score data if ($i == 0) { echo '<tr><td colspan="2" class="topscoreheader">Top Score: ' . $row['score'] . '</td></tr>'; } echo '<tr><td class="scoreinfo">'; echo '<span class="score">' . $row['score'] . '</span><br />'; echo '<strong>Name:</strong> ' . $row['name'] . '<br />'; echo '<strong>Date:</strong> ' . $row['date'] . '</td>'; if (is_file(GW_UPLOADPATH . $row['screenshot']) && filesize(GW_UPLOADPATH . $row['screenshot']) > 0) { echo '<td><img src="' . GW_UPLOADPATH . $row['screenshot'] . '" alt="Score image" /></td></tr>'; } else { echo '<td><img src="' . GW_UPLOADPATH . 'unverified.gif' . '" alt="Unverified score" /></td></tr>'; } $i++; } echo '</table>'; mysqli_close($dbc); ?> </body> </html>
×
×
  • 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.