Jump to content

craigerjs

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by craigerjs

  1. Another note, I just did a php info and all my GD stuff seems to be enabled. GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.2.1 GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XBM Support enabled
  2. Hi, I am making a CAPTCHA image. I am pretty sure the code I have is correct, but I am getting these error messages when I run the script. I use GoDaddy for hosting. The font that I reference in the script is in the root directory with the script. Any ideas? Thanks, Craig ------------ Warning: imagefilledrectangle(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 19 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagettftext() expects parameter 1 to be resource, null given in /home/content/68/6372768/html/captcha.php on line 30 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 35 <?php session_start(); // Set some important CAPTCHA constants define('CAPTCHA_NUMCHARS', 6); // number of characters in pass-phrase define('CAPTCHA_WIDTH', 100); // width of image define('CAPTCHA_HEIGHT', 25); // height of image // Generate the random pass-phrase $pass_phrase = ""; for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) { $pass_phrase .= chr(rand(97, 122)); } // Store the encrypted pass-phrase in a session variable $_SESSION['pass_phrase'] = sha1($pass_phrase); // Create the image $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 0, 0, 0); // black $graphic_color = imagecolorallocate($img, 64, 64, 64); // dark gray // Fill the background imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color); // Draw some random lines for ($i = 0; $i < 5; $i++) { imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Sprinkle in some random dots for ($i = 0; $i < 50; $i++) { imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Draw the pass-phrase string imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase); // Output the image as a PNG using a header header("Content-type: image/png"); imagepng($img); // Clean up imagedestroy($img); ?>
  3. Hi, I have a user sign up form. When some data is incorrect or missing it reloads the form, saving the info the user has already entered and displaying an error message for the parts that are invalid. For example: <tr><td width = "300"> <label for="email">Email Address:</label></td> <td><input type="text" id="email" name="email" value="<?php if (!empty($email)) echo $email; ?>" /><br /> </td></tr> How can I return the submitted info for a checkbox and a birthdate? Sorry, the birthdate code is kind of huge. <tr><td width = "300"> <label for="terms">I agree to the <a href = "/TOS.php">Terms of Service</a>.</label></td> <td><input type="checkbox" id="terms" name="terms" value = "checked"/><br /> </td></tr> <td> <select id = "DateOfBirth_Month" name="DateOfBirth_Month"> <option>Month</option> <option value="1">January</option> <option value="2">Febuary</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select id = "DateOfBirth_Day" name="DateOfBirth_Day"> <option>Day</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select id = "DateOfBirth_Year" name="DateOfBirth_Year"> <option>Year</option> <option value="2010">2010</option> <option value="2009">2004</option> <option value="2008">2003</option> <option value="2007">2002</option> <option value="2006">2001</option> <option value="2005">2000</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> <option value="1900">1900</option> </select> </td></tr> Thanks if you can help, Craig
  4. craigerjs

    SHA

    Hi, I have a $password that is encrypted with SHA. I have a $user_password that gets it's data from a form. How can I write an if statement comparing the two for equality? I am not sure how to make the $user_password into a SHA encrypted format within an if statement. Thanks, Craig
  5. Thanks, that worked. I just realized that if two people have the same password this idea won't work anyway. Gotta think of a better way to do this now.
  6. Hi, I have an image uploader here and I am trying to have a user enter their password and check a box in order to submit their image. I am having trouble validating the password. I get this error message: "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/68/6372768/html/submit.php on line 58" From this section of the code: $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } Anyone see what I am doing wrong? The password stored in my DB is encrypted with SHA. <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Submit an Image'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<center><table border="0" cellspacing = "20"><tr><td>'; echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; echo '</td></tr></table></center>'; // Insert the page footer echo '<div class="footer">'; require_once('footer.php'); echo '</div>'; exit(); } ?> <div class="linkrow"> <!-- end .linkrow --></div> <div class="contentBlue960"> <img src = "/IMAGES/WEBSITE/capBlue960.jpg"> <?php if (isset($_POST['submit'])) { // Connect to the DB $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Set password to false $valid_password = false; // Grab the id data from the POST $image_name = $_FILES['image_name']['name']; $image_name_type = $_FILES['image_name']['type']; $image_name_size = $_FILES['image_name']['size']; $user_password = (mysqli_real_escape_string($dbc, trim($_POST['user_password']))); $agree = mysqli_real_escape_string($dbc, trim($_POST['agree'])); // Grab the id data from the DB if (!isset($_GET['user_id'])) { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); $user_name = $row['user_name']; $password = $row['password']; $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } // If image and password are entered if (!empty($user_password) && !empty($image_name)) { // If the entered password matches the user's password if ($valid_password == true) { // If the copyright is agreed to if (($agree) == ('checked')) { // If the pic is valid if ((($image_name_type == 'image/gif') || ($image_name_type == 'image/jpeg') || ($image_name_type == 'image/pjpeg') || ($image_name_type == 'image/png')) && ($image_name_size > 0) && ($image_name_size <= GW_MAXFILESIZE)) { if ($_FILES['image_name']['error'] == 0) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $image_name; if (move_uploaded_file($_FILES['image_name']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Write the data to the database $query = "INSERT INTO user_images VALUES (0, '$user_name', NOW(), '$image_name')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for submitting an image! Under review as soon as possible.</p>'; echo '<p><strong>User Name:</strong> ' . $user_name . '<br />'; echo '<img src="' . GW_UPLOADPATH . $image_name . '" alt="Submitted Image" /></p>'; echo '<p><a href="submit.php"><< Back to submit page.</a></p>'; // Clear the id data to clear the form $user_name = ""; $image_name = ""; 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['image_name']['tmp_name']); } else { echo '<p class="error">Must agree with and check copyright box.</p>'; } } else { echo '<p class="error">Password Incorrect</p>'; } } else { // echo 'Pass' . $password . ' 1'; // echo 'User pass' . $user_password . ' 2'; // echo 'Checkbox' . $agree . ' 3'; // echo 'Username' . $user_name . ' 3'; echo '<p class="error">Please enter all of the information to add your image.</p>'; } } // mysqli_close($dbc); ?> <table border="1" cellspacing = "20"> <tr><td width = 960px><h2>Submit an Image</h2></td></tr> </table> <table border="1" cellspacing = "20"> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td width = "300"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="image_name">Image:</label></td> <td><input type="file" id="image_name" name="image_name" /> </td></tr> <tr><td width = "300"> <label for="user_password">Enter Password:</label></td> <td><input type="text" id="user_password" name="user_password" /><br /> </td></tr> <tr><td width = "300"> <label for="terms">This image is my own work and I own all copyrights to it.</label></td> <td><input type="checkbox" id="agree" name="agree" value = "checked"/><br /> </td></tr> <tr><td width = "300"> <input type="submit" value="Submit Image" name="submit" /> </td></tr> </form> </td> </tr> </table> <img src = "/IMAGES/WEBSITE/bottomBlue960.jpg"> <!-- end .contentWhite960 --></div> <div class="footer"> <?php // Insert the page footer require_once('footer.php'); ?> <!-- end .footer --></div> Thanks if you can help, Craig
  7. Hi, I am trying to build a rating system for images. I have a loop that displays the images and I want to add a voting option for each image. Right now when you vote on one image, the vote gets recorded for each image in the loop. How can I make the vote script unique for each image? Here is the script that displays the images: <?php // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Retrieve the id data from MySQL $query = "SELECT * FROM user_images ORDER BY id DESC, date ASC"; $data = mysqli_query($dbc, $query); // Loop through the array of id data, formatting it as HTML echo '<table border="0" cellspacing = "20">'; while ($row = mysqli_fetch_array($data)) { // Display the images from newest to oldest echo '<tr><td valign="top"width = 260px height = 600px>'; echo '<strong>User:</strong> ' . $row['user_name'] . '<br />'; echo '<strong>Date:</strong> ' . $row['date'] . '</td>'; if (is_file(GW_UPLOADPATH . $row['image_name']) && filesize(GW_UPLOADPATH . $row['image_name']) > 0) { echo '<td valign="top" width = 700px height = 600px>'; $vote_image_name = $row['image_name']; require('vote.php'); echo '<A HREF= "' . GW_UPLOADPATH . $row['image_name'] . '"><center><img style="border:2px solid black" width = "500px" src="' . GW_UPLOADPATH . $row['image_name'] . '" alt="Image Missing" /></a></center></td></tr>'; } else { echo '<td valign="top" width = 700px height = 600px><center><img style="border:2px solid black" src="' . GW_UPLOADPATH . 'unverified.gif' . '" alt="Unverified image" /></center></td></tr>'; } } echo '</table>'; mysqli_close($dbc); ?> And here is the vote script that gets called in: <?php // already Connected to the database // $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { $week = CURRENT_WEEK; $vote = mysqli_real_escape_string($dbc, trim($_POST['vote'])); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); $query = "INSERT INTO user_votes VALUES (0, '$week', '$vote_image_name', '$vote')"; mysqli_query($dbc, $query); echo '<p>Your vote has been recorded.</p>'; // mysqli_close($dbc); } ?> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo PIC_MAXFILESIZE; ?>" /> <fieldset> <legend>Vote</legend> <label for="vote">Vote:</label> <input type="radio" id="vote" name="vote" value="1" />1 <input type="radio" id="vote" name="vote" value="2" />2 <input type="radio" id="vote" name="vote" value="3" />3 <input type="radio" id="vote" name="vote" value="4" />4 <input type="radio" id="vote" name="vote" value="5" />5 </fieldset> <input type="submit" value="Vote" name="submit" /> </form> Thanks for any ideas you might have, Craig
  8. Hi, I am having trouble with displaying an array of images in Internet Explorer. Everything looks great in Firefox, but the pics line up on top of each other in IE. Does anyone have a solution? http://sketchweek.com/example.php Here's the piece of code: <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- TemplateBeginEditable name="doctitle" --> <title>SKETCHWEEK.COM - Friendly Competition for Friendly Artists!</title> <!-- TemplateEndEditable --> <!-- TemplateBeginEditable name="head" --> <!-- TemplateEndEditable --> <!-- Import Stylesheet --> <LINK REL="stylesheet" TITLE="Default Styles" HREF="style7.css" MEDIA="screen"> </head> <body> <div class="thumbs"> <center> <br> <br> <br> <?php require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Retrieve the id data from MySQL $query = "SELECT * FROM user_images ORDER BY id DESC, date ASC"; $data = mysqli_query($dbc, $query); // Loop through the array of id data, formatting it as HTML echo '<table>'; $picsRemaining = 7; while ($row = mysqli_fetch_array($data)) { if ($picsRemaining > 0) { if (is_file(GW_UPLOADPATH . $row['image_name']) && filesize(GW_UPLOADPATH . $row['image_name']) > 0) { echo '<A HREF= "' . GW_UPLOADPATH . $row['image_name'] . '"><img HEIGHT=100px WIDTH=100px src="' . GW_UPLOADPATH . $row['image_name'] . '" alt="Image" /></a> '; } else { echo '<td><img src="' . GW_UPLOADPATH . 'unverified.gif' . '" alt="Unverified image" /></td></tr>'; } $picsRemaining--; } } mysqli_close($dbc); ?> <br> <br> </center> <!-- end .thumbs --></div> </body> </html> Thanks, Craig
  9. Hi Ken, thank you so much for the reply. Problem solved! I appreciate it.
  10. Hi, I am having a problem with an image upload script. When I enter a user name, choose an image and press 'Add' I get my error message "Please enter all of the information to add your image." Nothing gets written to the database and the image is not uploaded to the folder I've specified. I am new to PHP and MySQL so if I have left out any info please let me know. Here is my code and SQL table: <!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>SKETCHWEEK.COM - Submit an image!</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>SKETCHWEEK.COM - Submit an image!</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_POST['submit'])) { // Grab the id data from the POST $user_name = $_POST['user_name']; $image_name = $_FILES['image_name']['user_name']; $image_name_type = $_FILES['image_name']['type']; $image_name_size = $_FILES['image_name']['size']; if (!empty($user_name) && !empty($image_name)) { if ((($image_name_type == 'image/gif') || ($image_name_type == 'image/jpeg') || ($image_name_type == 'image/pjpeg') || ($image_name_type == 'image/png')) && ($image_name_size > 0) && ($image_name_size <= GW_MAXFILESIZE)) { if ($_FILES['image_name']['error'] == 0) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $image_name; if (move_uploaded_file($_FILES['image_name']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Write the data to the database $query = "INSERT INTO user_images VALUES (0, '$user_name', NOW(), '$image_name')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for submitting an image! Under review as soon as possible.</p>'; echo '<p><strong>User Name:</strong> ' . $user_name . '<br />'; echo '<img src="' . GW_UPLOADPATH . $image_name . '" alt="Submitted Image" /></p>'; echo '<p><a href="submit.php"><< Back to submit page.</a></p>'; // Clear the id data to clear the form $user_name = ""; $image_name = ""; 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['image_name']['tmp_name']); } else { echo '<p class="error">Please enter all of the information to add your image.</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="user_name">Enter User Name:</label> <input type="text" id="user_name" name="user_name" value="<?php if (!empty($user_name)) echo $user_name; ?>" /><br /> <label for="image_name">Image:</label> <input type="file" id="image_name" name="image_name" /> <hr /> <input type="submit" value="Add" name="submit" /> </form> </body> </html> Thanks for looking, hope you can help! Craig
×
×
  • 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.