Jump to content

simcoweb

Members
  • Posts

    1,104
  • Joined

  • Last visited

Everything posted by simcoweb

  1. Just a quick note, I did modify your original code example to work with my form fields and also rearranged it a bit regarding the 'messages'. Ok, your chronological order is correct. It should check IF there's a blank... then if there's not then it should check that the fields contain the proper characters (validation), if that checks out then run the query and complete the process.  Now, it's actually doing the validation but as I mentioned it's submitting to the mysql even though there may be a validation error. The error is displayed and they are encouraged/told to correct the error and resubmit. Well, as it stands, if someone made a dozen errors then they will have submitted their data a dozen times. The 'empty($_POST) setup is really just a way to stop them from trying to submit the form with specific fields empty. It does not stop the form from running the query. That's the issue I really needs to resolve. The further validation and empty fields I can figure out. So, here's the lineup: * person enters all fields but the passwords don't match - PRODUCES VALIDATION ERROR * right there the form should STOP and not run the query * person reenters the data correctly, validation is ok, and form checks for duplicate username * IF the username already exists then it should STOP there and produce error 'username already exists. Please use another name'. * person reenters the data with new username, validation is good to go, username has no dupes, and form data gets submitted. * after submission they should be redirected to the 'login.php' page I know that validation is different than an empty field so I need them both. If there's nothing to validate then it could slide through. So, i'll input that code and test it. The part that's missing is the code to STOP the data insertion. Thanks again!
  2. Thanks, Wintergreen, for the further info. Actually I inserted your code but it produced parsing errors so i'm dealing with that. To answer the other questions, the empty 'else' statement was just repositioning some stuff. The 2nd 'IF statment should disappear and all those items to parse should go in there. This is my assumption, obviously. I placed your code at the beginning ahead of the current first IF statement. Since 'if' there's empty fields the validation shouldn't run anyway. The real problem has been that even though the 'if' statements check for validation and empty fields, the form was still inserting the data into the mysql database. The page would display a validation error, for example, but it was still submitting the data. If i'm understanding your code it's basically going to stop the form from being submitted if a field is empty. But, let's say there's no empty fields but we still get a validation error. Is it going to stop the form from inserting the mysql query? That's really the root of all this. Thanks again.
  3. Thanks for the further code tips and info. Unfortunately this is not exactly what I need. Here's some more details: [list] [*]I already have form field validation code that's working properly and displays the error messages if a particular field is left empty [*]The form submists the data to the database even though the input errors occur. In other words, the validation is not stopping the form from submitting the data into the database. [/list] So, what I need is specific code that says "Even though they pressed Submit and the field validation produced an error... do not submit the data to the database. Instead, return to the form, show the error, and only enter the data IF no validation errors occur" This is the entire section of code currently in use without errors. It performs the validation, uploads an image and inserts into the database. [code]// Validate users input if(!empty($_POST)) { // Check email is a valid email address if(isset($_POST['email'])) if(!ereg("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,}|[0-9]{1,})(\\]?)$", $_POST['email'])) $eg_error['email'] = "You must enter a valid email address!"; // Check password has a value if(empty($_POST['password'])) $eg_error['password'] = "You must enter a password!"; // Check that city is letters only if(isset($_POST['city'])) if(ereg("[0-9]", $_POST['city'])) $eg_error['city'] = "city must be letters only!"; // Check that confirmPass is the same as (comparison) if(isset($_POST['confirmPass'])) if($_POST['confirmPass'] != @$_POST['password']) $eg_error['confirmPass'] = "Your passwords do not match!"; // Check that username is numbers and letters if(isset($_POST['username'])) if(ereg("[!\"£\$%\^&\*()\+=\{}[.].][.[.]#~';:@/\.,<>\?\\| ]", $_POST['username'])) $eg_error['username'] = "The user name contains some illegal charactures, only use alpha-numeric charactures."; // Check username has a value if(empty($_POST['username'])) $eg_error['username'] = "You must enter a user name!"; // Check if any errors were returned and run relevant code if(empty($eg_error)) { } else { } } // Conditional statement if(!empty($_POST)) { // Upload File $eg_success_File1 = false; if(!empty($_FILES['photo']['name'])) { // Check file is not larger than specified maximum size $eg_allowUpload = $_FILES['photo']['size'] <= 100000 ? true : false; // Check file is of the specified type if($eg_allowUpload) $eg_allowUpload = preg_match('/\\.(gif|jpg|jpeg|png)$/i', $_FILES['photo']['name']) ? true : false; if($eg_allowUpload) { if(is_uploaded_file($_FILES['photo']['tmp_name'])) { $eg_uploaddir = $_SERVER['DOCUMENT_ROOT']."/images/photo/"; $eg_uploadFile1 = $eg_uploaddir.rawurlencode($_FILES['photo']['name']); // Create a unique filename for the uploaded file $eg_i = 1; while (file_exists($eg_uploadFile1)) { $eg_separated_filename = explode(".",$eg_uploadFile1); if (substr($eg_separated_filename[0],-1) == $eg_i) { $eg_separated_filename[0] = substr($eg_separated_filename[0], 0, (strlen($eg_separated_filename[0])-1)); $eg_i++; } $eg_separated_filename[0] = $eg_separated_filename[0] . "$eg_i"; $eg_uploadFile1 = implode(".",$eg_separated_filename); } $eg_success_File1 = move_uploaded_file($_FILES['photo']['tmp_name'], $eg_uploadFile1); } } } // Run query mysql_query("INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."')", $eg_objConn1); }[/code]
  4. That produces this error: [code]Parse error: parse error, unexpected '{' in /home2/wwwplat/public_html/register.php on line 16[/code] Which is the line right before it.
  5. This code is producing a T_Variable error on line 17. [code]$message = ""; if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmPass'])) {   if(empty($_POST['username'])   $message .= "You did not complete the username field properly.<br>\n";   if(empty($_POST['password'])   $message .= "You did not enter a correct password.<br>\n";   if(empty($_POST['confirmPass'])   $message .= "Your password entries did not match.<br>\n";[/code] Line 17 is [code]$message .= "You did not complete the username field properly.<br>\n";[/code]
  6. So do I have to name each 'form_element' or is there a global way to do it?
  7. Apparently not  ;D  I commented them out. Error go bye bye and images still show up. I guess I wasn't sure if the images were showing up because of that line since they started showing up at the same time I inserted it. However, I made about 4,000,324,234,212 changes to that page so keeping up with what worked got a little screwy about 2am. Thanks again for the help, Barand!
  8. Thanks for the response and tips. I'm not 100% sure I follow your suggestion so I need just a bit of clarification. So you're saying this new code should go ahead of the validation and make the validation part of an 'else' section?
  9. Hi Barand: In your first example that pertains to calling a single row. I'm actually calling all the rows in that table as an array and displaying them in a 'while' loop. The images show up fine. But that error shows at the top of the page. Take a peek: [url=http://www.plateauprofessionals.com/display.php]http://www.plateauprofessionals.com/display.php[/url] This: [code]$sql2=("SELECT photo FROM plateau_pros WHERE photo='photo'"); $result2 = mysql_query($sql2) or die(mysql_error()); $image = mysql_result($result2, 0, 'photo');[/code] is leading to this: [code]while ($row = mysql_fetch_assoc($result)) {   extract($row);   echo <<<HTML  blah blah blah[/code] and in the HTML is the image code: [code]<td style='padding-left: 10px; padding-right: 10px; padding-top:5px; padding-bottom:5px' width='229' valign='top'><img src='images/photo/$photo'  width='175' height='225'></td>[/code] In the mysql database there's no more 'imageName' field. Didn't need it so I deleted it. Also, the 'fileName' field I changed the title to 'photo'. Plus, edited all code to use that field name. Seems to work fine except for that error.
  10. I have a registration form that's using PHP validation. The problem is even though there may be errors in the field entries by the person registering it's still submitting to the mysql database. The form displays the error messages as to which fields they messed up or forgot. But, once they correct those and resubmit then it creates duplicate entries in the database. I need to know how to stop that. Thanks! Here's the validation code: [code]// Validate users input if(!empty($_POST)) { // Check email is a valid email address if(isset($_POST['email'])) if(!ereg("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,}|[0-9]{1,})(\\]?)$", $_POST['email'])) $eg_error['email'] = "You must enter a valid email address!"; // Check password has a value if(empty($_POST['password'])) $eg_error['password'] = "You must enter a password!"; // Check that city is letters only if(isset($_POST['city'])) if(ereg("[0-9]", $_POST['city'])) $eg_error['city'] = "city must be letters only!"; // Check that confirmPass is the same as (comparison) if(isset($_POST['confirmPass'])) if($_POST['confirmPass'] != @$_POST['password']) $eg_error['confirmPass'] = "Your passwords do not match!"; // Check that username is numbers and letters if(isset($_POST['username'])) if(ereg("[!\"£\$%\^&\*()\+=\{}[.].][.[.]#~';:@/\.,<>\?\\| ]", $_POST['username'])) $eg_error['username'] = "The user name contains some illegal charactures, only use alpha-numeric charactures."; // Check username has a value if(empty($_POST['username'])) $eg_error['username'] = "You must enter a user name!"; // Check if any errors were returned and run relevant code if(empty($eg_error)) { } else { } }[/code] I'm assuming it needs some additional 'if' coding in the 'else' area.
  11. Still getting this error message: [quote]Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 46 in /home2/wwwplat/public_html/display4.php on line 16[/quote] From this line: [code]$image = mysql_result($result2, 0, 'photo');[/code] Please advise. Thanks!
  12. Also, in the event that IF there's no pic uploaded for a person I want it to display a placeholder pic or text that says No Photo Available. A placeholder pic would be nicer. I'm not sure how to implement this but my simple-logic mind has something like this: $image = mysql_result($result2, 'imageFile'); [code]if (!isset ($image)) { echo "No Photo Available"; } [/code] Can someone point me in the right direction on having a substitute image to display? Thanks!
  13. Thanks, Zanus. The only problem with having 'a' global size is that I may want the uploaded image to be displayed in 2 or 3 different sizes depending on the page being viewed. That way I can have just one image uploaded but have it viewed as a thumbnail, medium sized or full sized image. In that code snippet it makes a reference to 'a' particular image. I need something that would point to the $imageFile or field name of the image used/uploaded by each individual. Can that be done?
  14. UPDATE: The images now are viewable and are coordinated with the proper profile! However, that error code is still present. So, I can either edit that line or if you have another suggestion...
  15. GLORY BE TO GOD! THE IMAGES SHOW! Now...one more question. HOW can I make those resize to a set of global dimensions? I mean, aside from putting in some height/width parameters, i'd like to have these 'resized' to the proper dimensions so I can keep their clarity and manipulate the display of these images from page to page. I have this function code I snagged but not sure how i'd adapt it to my needs. Here it is: [code]$mysock = getimagesize("images/photo/image_name_here"); // image resize function function imageResize($width, $height, $target) { /*takes the larger size of the width and height and applies the formula accordingly...this is so this script will work  dynamically with any size image */ if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the return "width=\"$width\" height=\"$height\""; }[/code] I would assume I could rename that '$mysock' variable and set the parameters to insert into the image src. Not sure. Guessing. Ideas?
  16. Barand, after inserting that line I get this error message: [quote]Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 46 in /home2/wwwplat/public_html/display.php on line 16[/quote] You can view the page here: [url=http://www.plateauprofessionals.com/display.php]http://www.plateauprofessionals.com/display.php[/url] Also note that the characters '; show up to the right of where the image should be displayed. This should be the closing of the echo statement but for some reason it's displaying it as text.
  17. Here's line 40 and up to 51: [quote]while ($row = mysql_fetch_assoc($result)) {   extract($row);   echo <<<HTML <div align='center'> <table border='0' cellpadding='0' style='border-collapse: collapse' width='530'> <tr><td colspan='2' background='http://www.plateauprofessionals.com/images/top2.gif' width='530' height='35' style='padding: 10px'><h2>$name</h2> </td> </tr><tr> <td height='15' colspan='2'> </td> </tr> <tr>[/quote]
  18. Yes, there is a 'memberid' column/field in the database. Also, I may be wrong with the 'imagename' field. That may be an actual name like 'My Dog Charlie' instead of the actual filename. There's another field called 'fileName' that contains the image name so that needs to be switched. Just a note, though, the same data is in both fields presently so it would call the image in either case. Now, i'm not 100% sure if i'm understnading the 'WHERE' part. My understanding is that i'm 'connecting' or 'referring' the [b]imageName[/b] to the member's ID ( 'memberid' ) so that it knows which one to display for which member. I'll admit i've been wrong on 99.9999% of my assumptions so that's probably another one. So, bottom line is i'm not 100% sure how i'd write that part of the query.
  19. Ok, makes sense. Then how would I call the image? Seems everything I try turns to mush. Example, please?
  20. AndyB, i've tried about 97 variations of that type of call. The database does NOT contain the file path. Only the file name (like '4202842.jpg' for example) I've inserted your suggestion and get this error when doing so: [code] Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home2/wwwplat/public_html/display.php on line 51[/code] Line 51 is this: [code]<td style='padding-left: 10px; padding-right: 10px; padding-top:5px; padding-bottom:5px' width='229' valign='top'><? echo "<img src='images/photo/". $row['imageFile']. "'>"; ?></td>[/code]
  21. jwwceo, thanks for that suggestion. I have thought of that as well. That would involve having some type of 'listing' or 'summary' page where visitor sees a category, clicks on it, then that displays a short blurb about each person with a link to their profile which would then show everything. That would allow me to use your method which might be the better way to go. I had no idea this was so complicated. I was assuming I could just use an echo statement that included the image path and a variable set to call the image. But that ain't workin. Any further guidance you can provide?
  22. I changed the title. Sorry for being a little wild with that one. Ok, I understand what you're saying. I need to generate some type of 'id' flag to call the images that correspond to the proper profile. Question is... how? I've searched until my eyeballs have bugged out of my skull. Most of the info is about calling up pics into a gallery or displaying all the pics in a folder. Basically here's what i've got: user registers and registration form includes photo upload user can log in to change their information if they wish photo gets uploaded to /images/photo folder My 'display.php' page pulls each person's profile into the page and displays it in some semi-fancy html output. I've gotten all the detail stuff to show. What I can't figure out is how to set up the image system so that they will show. So.. some guidance/examples/tutorials/code snippets would be MUCH appreciated. Thanks!
  23. I'm at a complete standstill with finishing a project where I have to display an image of each person that's a member of a modest sized organization (about 25 people). I have the pictures uploading fine to the proper directory on the server. I even have the file name inserted into the Mysql database. What I can't figure out is HOW to call the proper image for the right person. The image file name is in the same table row as the other information about the person (name, username, phone, etc.) Perhaps I should have a separate table for the images with an image_id field that is auto-incremented and connect the person to the image_id? I'm looking for some help here on where to go from here. The page i'm putting this into is here: http://www.plateauprofessionals.com/display.php This is driving me NUTS as i've spent literally 5 days researching and testing. Help?
  24. Not much hair left! This is getting really frustrating as i've tried SOOOOOOOO many angles on this. Ok, here's the latest. First, here's the 'official' display page for the profiles and images utilizing some dummy people entered into the database. The first entry has an image file named in the 'imageName' field. The others don't. I'm using this tag to summon the pic: <?php echo '<img src="http://www.plateauprofessionals.com/images/photo/' . $image . '" width='150' height='175'>'; ?> You can view the page here: http://www.plateauprofessionals.com/display.php For some reason it's displaying the ';? where the image should display. That's problem #1 Now, when I change the image tag to remove the <?php echo code and just have the following: [quote]http://www.plateauprofessionals.com/images/photo/' .  $image . '[/quote] Then the red x box shows but no image. So, if you check the properties (right click/properties) it shows this URL to the image: [quote]http://www.plateauprofessionals.com/images/photo/'%20.%20%20.%20'[/quote] I've even created a second sql query just for the images: [code]$sql2=("SELECT imageName FROM members WHERE imageName='memberid'"); $result2 = mysql_query($sql2) or die(mysql_error());[/code] And set a variable as: $image = $sql['imageName']; No matter what i've done/do I can't get this simple friggin image to show up. Help?
  25. http://www.plateauprofessionals.com/images/photo/42-15602495.jpg is the direct link. Also, I rewrote the 'getimage.php' so it would just display the entries in the 'File1' image field. There's only 3 entries in that field in that table. It displays the image names. Check it out: http://www.plateauprofessionals.com/getimage.php Here's the code for it. Excuse the sloppiness as i've made several revisions to it: [code]<?php include 'config.php'; mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = "SELECT File1 FROM  plateau_pros"; mysql_query($sql); $Result = mysql_query($sql); echo "<table>"; while ($a_row = mysql_fetch_array( $Result )) {   echo "<tr><td>" . $a_row['File1'] . "</td></tr>\n"; } echo "</table>"; ?>[/code]
×
×
  • 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.