rmelino Posted July 21, 2009 Share Posted July 21, 2009 Hello, I'm a beginner-intermediate with php. I have a php driven website where users have profile pages. Currently, they submit their profile page edits through a php script that emails me the changes. I manually make those changes for users by updating the db. I'd like to set up the site with logins and pwds for each user and allow them the ability to make changes to their own profile pages. Could anyone steer me in the right direction for good tutorials that address this issue? Thanks! Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/ Share on other sites More sharing options...
StefanRSA Posted July 21, 2009 Share Posted July 21, 2009 http://evolt.org/PHP-Login-System-with-Admin-Features?from=0&comments_per_page=50 But the following one might help for what you are looking for: Tutorial Description: In this multi-page article you'll be shown how to set up the server side scripting for a complete membership system, including everything from registration, to changing your password, validation emails, etc. http://biorust.com/tutorials/detail/118/us/ Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-879853 Share on other sites More sharing options...
papillonstudios Posted July 21, 2009 Share Posted July 21, 2009 thats a good tutorial but heres the code made for this exact thing. In my edit Profie its a the simplest. I have fields that have all the data the the user has provide like email, msn, gtalk, jabber etc. HEres my form code <form method="post"> <table width="50%"> <tr><td>Location: <?php echo ''.form_input(text,location,$uLocation, 25, 25).''; ?> </td></tr> <tr><td>MSN Messenger: <?php echo ''.form_input(text,msn,$uMsn, 25, 30).''; ?> </td></tr> <tr><td>AOL Messenger: <?php echo ''.form_input(text,aim,$uAim, 25, 30).''; ?> </td></tr> <tr><td>GTalk: <?php echo ''.form_input(text,gtalk,$uGtalk, 25, 30).''; ?> </td></tr> <tr><td>Email: <?php echo ''.form_input(text,email, $uEmail, 25, 30).''; ?> </td></tr> <tr><td></td></tr> <tr><td>Bio: <?php echo ''.form_textarea(40,10,bio, $uBio).''; ?></td></tr> <tr><td><?php echo ''.form_button(submit, update, Update).''; ?></td></tr> </table> </form> the functions in that code are one s that i have made, but the code just displasy a series of text boxes or text areas that has the data thats in the database. before the form i have this code check if the form has be submitted //If the form hasn't been submitted, show it. if (!$_POST['update']) { and heres the code that used to put it in the database <?php } //Or else it has been submitted... else { //Get information from the forums, secure it all. $location = secure($_POST['location']); $msn = secure($_POST['msn']); $aim = secure($_POST['aim']); $gtalk = secure($_POST['gtalk']); $email = secure($_POST['email']); $bio = secure($_POST['bio']); $update = @mysql_query("UPDATE users SET email = '$email', location = '$location', aim = '$aim', msn = '$msn', gtalk = '$gtalk', bio = '$bio' WHERE username = '$uName'"); if ($update) echo 'Your profile has been updated'; else echo 'MySQL error'; In here i defines some variables and put the data from the fields into the corresponding variable. Heres the whole script, you can use it without crediting me if you like, or you can just use it as a reference. //If the form hasn't been submitted, show it. if (!$_POST['update']) { ?> <form method="post"> <table width="50%"> <tr><td>Location: <?php echo ''.form_input(text,location,$uLocation, 25, 25).''; ?> </td></tr> <tr><td>MSN Messenger: <?php echo ''.form_input(text,msn,$uMsn, 25, 30).''; ?> </td></tr> <tr><td>AOL Messenger: <?php echo ''.form_input(text,aim,$uAim, 25, 30).''; ?> </td></tr> <tr><td>GTalk: <?php echo ''.form_input(text,gtalk,$uGtalk, 25, 30).''; ?> </td></tr> <tr><td>Email: <?php echo ''.form_input(text,email, $uEmail, 25, 30).''; ?> </td></tr> <tr><td></td></tr> <tr><td>Bio: <?php echo ''.form_textarea(40,10,bio, $uBio).''; ?></td></tr> <tr><td><?php echo ''.form_button(submit, update, Update).''; ?></td></tr> </table> </form> <?php } //Or else it has been submitted... else { //Get information from the forums, secure it all. $location = secure($_POST['location']); $msn = secure($_POST['msn']); $aim = secure($_POST['aim']); $gtalk = secure($_POST['gtalk']); $email = secure($_POST['email']); $bio = secure($_POST['bio']); //A query to update everything $update = @mysql_query("UPDATE users SET email = '$email', location = '$location', aim = '$aim', msn = '$msn', gtalk = '$gtalk', bio = '$bio' WHERE username = '$uName'"); if ($update) echo 'Your profile has been updated'; else echo 'MySQL error'; } Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-879881 Share on other sites More sharing options...
rmelino Posted July 22, 2009 Author Share Posted July 22, 2009 StefanRSA, I went through the BioRust tutorial and it was helpful--thank you. I have successfully made it so I can create a user / pwd and access the 'member page' as shown in the tutorial. I think what I'm missing now is how to tie the two together. So right now, let's say the url of a particular member of my website is this: http://www.mysite.com/member.php?id=1456. Let's also say that this member url is a public page that displays member name, member phone, and member address. I'd like to be able to have member with id=1456 to be able to create a user and password and then be able to edit the contents (member name, member phone, and member address) that show up on their page (http://www.mysite.com/member.php?id=1456) Hopefully what I'm asking makes sense. If you have any additional assistance it would be greatly appreciated. In the meantime, i'll keep plugging away at it myself! Thanks- Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-879905 Share on other sites More sharing options...
rmelino Posted July 22, 2009 Author Share Posted July 22, 2009 gfadmin, Thanks for the code to try. I attempted it but keep getting the following error: Fatal error: Call to undefined function form_input() Is there something i am missing in your code? Thanks, Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-879908 Share on other sites More sharing options...
papillonstudios Posted July 22, 2009 Share Posted July 22, 2009 gfadmin, Thanks for the code to try. I attempted it but keep getting the following error: Fatal error: Call to undefined function form_input() Is there something i am missing in your code? Thanks, The reason why thats happening is that you dont have that function. create a file called functions.php and put this code into it. They are very simple to use and code. //Images Function function image($src='', $alt='' , $border='') { return '<img src="'.$src.'" alt="'.$alt.'" border"'.$border.'">'; } //Anchor Function function anchor ($link, $text) { return '<a href="'.$link. '">'.$text.'</a>'; } //Input Field Function function form_input ($type='', $name='', $value='', $size='', $max='') { return '<input class="textfield" type="'.$type.'" size="'.$size.'" maxlength="'.$max.'" name="'.$name.'" value="'.$value.'">'; } //Checkbox Function function form_checkbox ($name) { return '<input class="textfield" type="checkbox" name="'.$name.'">'; } //Textarea Function function form_textarea ($cols='', $rows='',$name='', $value='') { return '<textarea cols="'.$cols. '" rows="'.$rows.'" class="textbox" name="'.$name .'">'.$value.'</textarea>'; } //Button Function function form_button ($type='',$name='',$value='') { return '<input type="'.$type.'" name="'.$name.'" value="'.$value.'">'; } I will also through in my typography function so if you want to format your text like forum software does like what i have now with all my paragraphs serperate. To use it just do this <?php //Example 1 using just a string typography('The String'); Example 2 using a variable typography ($string)'' ?> the function //Typography Function // do nl2br except when in a pre tag function typography($string) { // First, check for <pre> tag if(!strpos($string, "<pre>")) { return nl2br($string); } // If there is a <pre>, we have to split by line // and manually replace the linebreaks with <br /> $strArr=explode("\n", $string); $output=""; $preFound=false; // Loop over each line foreach($strArr as $line) { // See if the line has a <pre>. If it does, set $preFound to true if(strpos($line, "<pre>")) { $preFound=true; } elseif(strpos($line, "</pre>")) { $preFound=false; } // If we are in a pre tag, just give a \n, else a <br /> if($preFound) { $output .= $line . "\n"; } else { $output .= $line . "<br />"; } } return $output; } Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-880317 Share on other sites More sharing options...
papillonstudios Posted July 22, 2009 Share Posted July 22, 2009 and dont forget to include that functions.php file <?php include ('functions.php'); ?> if you have a config.php or something like that, that is included on every page, put the code there if not then in the the file that has my code in it. and if you know about the include php function you know that you have to put the url to the file in where i put functions.php for example if its located under the config folder <?php include ('config/functions.php'); ?> Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-880332 Share on other sites More sharing options...
rmelino Posted July 23, 2009 Author Share Posted July 23, 2009 Thank you very much for the tips. I'm finally getting somewhere! I appreciate all the help... Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-881270 Share on other sites More sharing options...
rmelino Posted July 23, 2009 Author Share Posted July 23, 2009 hi again gfadmin, So i had an additional question. Using your code you posted i have things working perfectly. The only issue i am having is that when a user is updated fields within their profile, if they leave one blank, it ends up deleting the previous data in the database for whatever field was left blank. For example: Lets say you had the following textboxes on the member profile edit page: Name: _______ Address: ______ Phone: ______ If the user wanted only to change their phone number but leave Name and Address the same, if they went in and put in a new phone number and left Name and Address blank and then hit submit, the script would update the phone number to the new number but since Name and Address were left blank it would erase whatever data was in the database under Name and Address. I assume it's some sort of if statement that needs to be inserted to say if field is left blank, make no change to entry. Can you help with this problem? Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-881558 Share on other sites More sharing options...
papillonstudios Posted July 28, 2009 Share Posted July 28, 2009 yes i can with my function you can define a value to be put in the field. so in you case lets say the users: address = $address name - $name phone = $phone for the function you would do this <?php //function at the raw form_input (['type'],[' name'],['value']) //function use example echo ''.form_input (text, name, $name).''; echo ''.form_input (text, address, $address).''; echo ''.form_input (text, phone, $phone).''; hopefully that helps Link to comment https://forums.phpfreaks.com/topic/166868-need-a-tutorial-for-authentication-and-an-editable-user-profile-page/#findComment-884645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.