Jump to content

dspurg7310

New Members
  • Posts

    5
  • Joined

  • Last visited

dspurg7310's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Trying to find a way to combine two scripts. 1. picture upload script that uploads the picture, gives it a new unique name, saves it to a specified directory and saves the unique name path to a user database (basically a user profile picture upload). and 2. A larger user login script I already have worked into my website that allows users to register on the site, view and edit their profile, log in, log out, etc. The issue is in part that I don't understand PHP well enough to figure out how to work these in together and the other part is that they are written a bit differently from each other so it's making it hard to combine them. One of the user profile fields I am using with script 2 is valued "bpic" and is where path to the uploaded picture would go. I have been successful in getting the unique path to save in that field in the database but absolutely can NOT seem to get the picture to actually upload and save in the "avatars" directory no matter what I try. I have determined that because my user script already calls the database, has an "INSERT INTO" database command and has error and success messages, I could take out those aspects of the picture uploading code below so I'm just trying to figure out where to place the "$new_image_name =" and "$bpic = " lines and how and where to code in the "move_uploaded_file" portion so the file actually uploads lol. (These are the two portions of the script below that I have decided I need to use and find a place to paste): $new_image_name = md5( rand (0, 1000) . rand (0, 1000) . rand (0, 1000) . rand (0, 1000) ) .'.jpg'; $bpic = 'avatars/' . $new_image_name; if(move_uploaded_file($_FILES['bpic']['tmp_name'], $bpic)) { } Any help and direction is appreciated! I have been at this for weeks with no success. It took me a while to actually get the picture upload script to work on it's own and upload the file, give it a unique name and save that unique name in both the directory and database so it can be found and displayed correctly. But anyway, the upload picture script works perfect now on it's own, but I gotta figure out how to place it in the script I already have. Upload Picture Script: (note: "bpic" is the field name of the file upload on the form and "$bpic" both references the field in the database and the file path to be created for the pic.) <?php //This is the directory where images will be saved $new_image_name = md5( rand (0, 1000) . rand (0, 1000) . rand (0, 1000) . rand (0, 1000) ) .'.jpg'; $bpic = 'avatars/' . $new_image_name; // Connects to your Database mysql_connect("businessdb1.db.9878324.hostedresource.com", "businessdb1", "Spidey148!") or die(mysql_error()) ; mysql_select_db("businessdb1") or die(mysql_error()) ; //Writes the photo to the server if(move_uploaded_file($_FILES['bpic']['tmp_name'], $bpic)) { //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$bpic')") ; //Tells you if its all ok echo "The file has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> As far as the user upload script goes, I'm not sure which page to work this code into so I don't want to make this post insanely long by posting every potential page (database.php - which I think is it, process.php, session.php, constants.php). The exact same code I am using is downloadable for free here: http://blog.geotitles.com/2011/07/php-login-script/ so you can see exactly how my code is formatted. I understand that's a lot of information and actually quite a bit of work for someone to look at and offer help, but if anyone is up to it, I would really appreciate any advice and help with this as I have been pulling out my hair trying to figure this out and it's going to completing a website that a lot of bands are waiting to sign up for! Thanks so much for your time! -David.
  2. So what is the "signature" thing? Is that something else I would need to download and install as well? I am very new at PHP and need the installation be be pretty simple lol
  3. But would it be simple to add additional fields to? I am new at it and what I am going to use it for would be good practice for the introduction into PHP scripting. I was hoping to integrate a First Name, Last Name and Location field into it. Is that possible with this kind of script?
  4. Thanks for the responses! I completely spaced the rest of the code. The login I am using is from here: http://blog.geotitles.com/2011/07/php-login-script/
  5. I have been exploring a PHP login form. It's pretty simple for the most part and I like it. I have had a lot of trouble trying to find out how to add additional fields to the form to store additional information about a user in the database such as First Name, Last Name, etc. And more recently I have been working on form integration so when a user is logged into their account and wants to submit a form, the PHP will grab their information from their account and add it to the form so they don't have to. Example: With a contact form I have added a hidden "Username" field. If the user is logged in, it grabs their username from their session and includes it in the email, if the user is not logged in or has no account, it simply adds a message to that spot on the email that basically says "Non-Member or not logged in". I want to do something similar with the email. If the user is logged in, I want the email field to grab their email - which I got it to do, but I wanted to take it a step further and if they are a user, it not only grabs their email but makes the email field hidden (like the username) but if they are not a member or not logged in, it shows them an email form to type in. I got the PHP to grab the email & hide the form when logged in but the form will not submit. When logged out, it shows the email field and everything submits fine. This is the code I came up with and I'm not sure how I could correct it to allow the form to submit: <h1>Email Us</h1> <form name="contactform1" method="post" action="send_contact_email.php" border="0"><fieldset> <p><label for="first_name">First Name *</label><br /> <input name="first_name" maxlength="50" size="25" type="text" /></p> <input type="hidden" name="user_name" maxlength="50" value=" <?php if($session->logged_in){ echo $session->userinfo['username']; }else{ echo "Non-Member or not logged in"; } ?>"> <p><label for="last_name">Last Name </label><br /> <input name="last_name" maxlength="50" size="25" type="text" /></p> <p> <?php if($session->logged_in){ ?> <input type="hidden" name="email" maxlength="50" size="25" value=" <?php echo $session->userinfo['email']; ?>" DISABLED> <?php } else { ?> <label for="email">Email Address *</label><br /><input type="text" name="email" maxlength="50" size="25" value=""> <?php } ?> </p> <p><label for="location">Location</label><br /> <input name="location" maxlength="80" size="25" type="text" /></p> <p><label for="comments">Message *</label><br /> <textarea name="comments" wrap="soft" rows="2" cols="50" type="textarea"></textarea></p> <p><input value="Submit" type="submit" /> <input value="Clear" type="reset" /></p> </fieldset></form>
×
×
  • 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.