PHP - Common Practice To Make Avatar And Nickname Permanently Visible?
I'm showcasing user avatars and nicknames on the page, the mistake I did was I used session variables for that which are being set after login, now obviously those will be deleted as soon as the session is over.
So I thought of inserting the values into scalar variables instead of session variables. The problem I'm encountering is, how to make those variables available at the necessary spots on other pages? Let's say I fetch data off the database after login inside login.php and I put the data into scalar variables, what would be common practice to make those scalar variables accessible in index.php? Is this solution a good solution at all to make the avatar and nickname of the user permanent visible? What would be common practice? Similar TutorialsHello I need help with making our dropdown links stay visible when active. Site: London tshirt .com Code: [Select] <dl id="nav"> <dt class="nav"><b>London Tshirts</b></dt> <dd> <ul> <li><a href="/Unisex">Unisex</a></li> <li><a href="/Slimfit">Slimfit</a></li> <li><a href="/Kids">Kids</a></li> </ul> </dd> <dt class="nav"><b>Alternative Tshirts</b></dt> <dd> <ul class="nav"> <li><a href="/England">England</a></li> <li><a href="/Humour">Humour</a></li> <li><a href="/Popular">Popular</a></li> </ul> </dd> <dt class="nav"><b>Magnets</b></dt> <dd> <ul class="nav"> <li><a href="/magnets-ceramic">Ceramic</a></li> <li><a href="/magnets-metal">Metal</a></li> <li><a href="/magents-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Keyrings</b></dt> <dd> <ul class="nav"> <li class="current"><a href="/keyrings-ceramic">Ceramic</a></li> <li class="current"><a href="/keyrings-metal">Metal</a></li> <li><a href="/keyrings-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Other gifts</b></dt> <dd> <ul class="nav"> <li><a href="/Hats">Hats</a></li> <li><a href="/Models">Models</a></li> <li><a href="/Bags">Bags</a></li> </ul> </dd> </dl> Thanks P.S. I typed my question, then went to verification, but could not read the letters so requested a new image, this refreshed the page and I lost my message?? Hi everyone, I need some help. I have made a comment system, where users have to be logged in to post their comments. I am stuck at displaying an avatar for each user. What I am trying to do is, there is a table for users login details and their avatar than there is a table for comments. I would like to do is take the users avatar from the login table and post it in the comments table, when the user comments, so I can echo different avatars, depending on who commented, if there is a different more simpler way I would like to know it. Thanks in advance. Hi, not sure if this is the correct forum, so apologies, i assumed it was a php problem. Anyway, all of the pages on my site are permanently loading. http://dev.subverb.net contains a few external scripts from twitter and facebook, so I assumed it could be that, but even ones like http://dev.subverb.net/mix.php always are loading. I can't figure out on firebug how to find what is loading, because it doesnt seem to tell me in the net profile, just what has already been loaded. Any help? Hi guys, im just trying to work out an app in my head and on paper. im just wondering.. when a user registers they can choose an Avatar 100px by 100px jpg, when they upload one would i then grab the file and store all Avatars in a avatar image folder and rename it to something like.. avatar[user_id].jpg and keep them all in the same folder. or would i crate a folder called users, each user gets their own folder with files like avatar.jpg and it finds the [user_id] folder and pulls the avatar out from that, or is there a more prefered method? cheers try to install orm peewee on opensuse 13. 1 but unfortunatly it failed martin@linux-70ce:~> martin@linux-70ce:~> git clone https://github.com/coleifer/peewee.git Klone nach 'peewee'... remote: Reusing existing pack: 5673, done. remote: Counting objects: 13, done. remote: Compressing objects: 100% (13/13), done. remote: Total 5686 (delta 2), reused 0 (delta 0) Empfange Objekte: 100% (5686/5686), 3.54 MiB | 102.00 KiB/s, done. Löse Unterschiede auf: 100% (3468/3468), done. Prüfe Konnektivität... Fertig martin@linux-70ce:~> cd peewee martin@linux-70ce:~/peewee> python setup.py install running install error: can't create or remove files in install directory The following error occurred while trying to add or remove files in the installation directory: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/test-easy-install-5717.write-test' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /usr/lib/python2.7/site-packages/ Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable. For information on other options, you may wish to consult the documentation at: https://pythonhosted.org/setuptools/easy_install.html Please make the appropriate changes for your system and try again. martin@linux-70ce:~/peewee> what can i do now Hi i have a chat written in php and as3 at the moment the chat window shows username and message but i want to add a avatar before the username. here is the code i have. $sql = mysql_query("SELECT * FROM chat75 ORDER BY date_time ASC"); while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $user_name = $row["user_name"]; $chat_body = $row["chat_body"]; $num = $row["avatar"]; $date_time = $row["date_time"]; $chat_body = stripslashes($chat_body); $chat_body = eregi_replace("'", "'", $chat_body); $string =array(); $files = glob("../images/avs/*.*"); for ($i=1; $i<count($files); $i++) { $num = $files[$i]; } $body .= '<b><font color="#006699">' . $num . ': ' . $user_name . ': <font color="#000000"> ' . $chat_body . '</font> <br />'; } this is what i get in the chat window ../images/avs/avatar9.png: demo123: testing message i have tried everything to get the avatar to appear in the chat window but keep getting the above,i have tried to put echo in front but then just get a blank chat window. please help thanks I need some help with my commenting system. at the moment the code is like this: <div id="pagepannel"> <div id="ptop_small">Comments</div> <div id="pbottom_small"> <p> <?php // if ($allow_comments == "no") { ?> </p> <p>No Posting comments here!!!</p> <p> </p> <p> </p> <p> <?php } else ?> </p> <p> <?php $sql = "SELECT comment_id, blog_id, posted_by, comment, stamp, email, type FROM jscrgaming_newscomments WHERE blog_id='$blog_id' ORDER BY comment_id DESC"; $result = mysql_query($sql) or die('Error : ' . mysql_error()); while(list($comment_id, $blog_id_co, $username, $comment, $stamp, $email, $type) = mysql_fetch_array($result, MYSQL_NUM)) { if ($type == 'user'){ ?> </p> <table width="95%" border="0" cellpadding="0" cellspacing="0" class="full_border"> <tr> <td width="75" id="avatar"></td> <td><span class="capitalize"><a href="userinfo.php?user=<? echo $username ?>"><strong><? echo $username ?></strong></a></span><strong> posted</strong>: <? echo stripslashes($comment) ?></td> </tr> <tr> <td colspan="2" bgcolor="#CAE4FF" class="date"><? echo $stamp ?> </td> </tr> </table> <p> </p> <p> <? } else{ ?> </p> <table width="95%" border="0" cellpadding="0" cellspacing="0" class="full_border"> <tr> <td><strong> <? echo $username ?>posted</strong>: <? echo stripslashes($comment) ?></td> </tr> <tr> <td bgcolor="#CAE4FF" class="smalltext"><? echo $stamp ?>:: User Was Guest</td> </tr> </table> <p> </p> <p> <? } }?> </p> <p> <?php // if ($allow_comments == "restricted") { /** * User has already logged in, so display relavent links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){?> </p> <form id="form3" name="form3" method="post" action="user/admin/blog/comment_system/user.php"> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td colspan="2">You are commenting as <?php echo $session->username;?></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="co_comment" cols="30" id="textfield10"></textarea></td> </tr> <tr> <td width="75"><span class="header"> <input name="co_username" type="hidden" id="co_username" value="<?php echo $session->username;?>" /> <input name="co_blog_id" type="hidden" id="co_blog_id" value="<?php echo $blog_id ?>" /> </span></td> <td><label> <input type="submit" class="blog_button" value=" Post " /> </label></td> </tr> <tr> <td> </td> <td class="smalltext">only 200 charaters can be used</td> </tr> </table> </form> <p> </p> <p> <? } else {?> </p> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td width="75"><span class="capitalize">Name</span></td> <td><label> <input name="textfield5" type="text" disabled="disabled" id="textfield5" size="35" /> </label></td> </tr> <tr> <td width="75">Email</td> <td><input name="textfield5" type="text" disabled="disabled" id="textfield6" size="35" /></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="textfield5" cols="30" disabled="disabled" id="textfield7">You need to be logged in to comment.</textarea></td> </tr> <tr> <td width="75"> </td> <td><label> <input type="button" class="blog_button" value=" Post " /> </label></td> </tr> </table> <p> </p> <p> <?php } } else { if($session->logged_in){?> </p> <form id="form2" name="form2" method="post" action="user/admin/blog/comment_system/user.php"> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td colspan="2">You are commenting as <?php echo $session->username;?></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="co_comment" cols="30" id="textfield8"></textarea></td> </tr> <tr> <td width="75"><input name="co_username" type="hidden" id="co_username" value="<?php echo $session->username;?>" /> <input name="co_blog_id" type="hidden" id="co_blog_id" value="<?php echo $blog_id ?>" /></td> <td><label> <input type="submit" class="blog_button" value=" Post " /> </label></td> </tr> <tr> <td> </td> <td><span class="smalltext">only 200 charaters can be used</span></td> </tr> </table> </form> <p> </p> <p> <? } else { ?> </p> <form id="form1" name="form1" method="post" action="user/admin/blog/comment_system/guest.php"> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td width="75"><span class="capitalize">Name</span></td> <td><label> <input name="co_username" type="text" id="co_username" size="35" /> </label></td> </tr> <tr> <td width="75">Email</td> <td><input name="guest_email" type="text" id="guest_email" size="35" /></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="co_comment" cols="30" id="co_comment"></textarea></td> </tr> <tr> <td width="75">Spam</td> <td> </td> </tr> <tr> <td colspan="2" align="center"><? require_once('user/captcha/recaptchalib.php'); $publickey = "6Ld_W7sSAAAAAPNTLWrUJLEClFpSSPu1d1Ry5zNR"; // you got this from the signup page echo recaptcha_get_html($publickey); ?></td> </tr> <tr> <td colspan="2" align="right"><span class="smalltext">only 200 charaters can be used</span> <input name="co_blog_id" type="hidden" id="co_blog_id" value="<?php echo $blog_id ?>" /> <input type="submit" class="blog_button" value=" Post " /></td> </tr> </table> </form> <p> </p> <p> <? } } ?> </p> <p> </p> <div></div> </div> </div> I, know its a bit messy but lets me see it and design it in Dreamweaver Any way, for the comment system for users, I want it to show their avatar as well, which is stored in the users table. How would one do this. I did think of it submitting the avatar along with the post but then it wouldnt update if the user would to change their avatars :\ Any helps??? Hey guys I have this script that edits a users profile, but the problem is that it doesnt want to upload it to the server and keeps saying. Files must be either JPEG, GIF, or PNG and less than 10,000 kb <?php if(empty($_GET['id']) ) { echo 'Category not specified'; } else { mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("chat"); $result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'"); $query = mysql_fetch_array($result); if (isset($_POST['submit'])) { $target = "mainnewsimg/"; $target = $target . basename( $_FILES['photo']['name']); // Set global variables to easier names $pic=($_FILES['photo']['name']); if (($_FILES["photo"]["type"] == "image/gif") || ($_FILES["photo"]["type"] == "image/jpeg") || ($_FILES["photo"]["type"] == "image/png" ) && ($_FILES["photo"]["size"] < 10000)) { if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { mysql_query("UPDATE users SET level ='". $_POST['rank'] ."', email='". $_POST['email'] ."', fname='". $_POST['fname'] ."', lname='". $_POST['lname'] ."', avatar='$pic' WHERE user_id='". $_GET['id'] ."' "); echo "user updated"; } else { echo "file hasent been moved to uploads"; } } else { echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb"; } //mysql_query("UPDATE Persons SET level = '36'WHERE user_id = '$_GET[id]'"); } ?> <?php echo $query['username']; ?> <form method="post" action=""> <table> <tbody> <tr><td class="first"></td> <td><?php echo $query['user_id']; ?></td></tr> <tr><td class="first">First Name</td> <td><input type="text" name="fname" value="<?php echo $query['fname']; ?>" ></td></tr> <tr><td class="first">Last Name</td> <td><input type="text" name="lname" value="<?php echo $query['lname']; ?>" ></td></tr> <tr><td class="first">Email</td> <td><input type="text" name="email" value="<?php echo $query['email']; ?>" ></td></tr> <tr><td class="first">Rank</td> <td><select name="rank"> <option value="0" <?php if($query['level']=="0") { echo "selected"; }?>>Unactivated</option> <option value="1" <?php if($query['level']=="1") { echo "selected"; }?>>Banned</option> <option value="2" <?php if($query['level']=="2") { echo "selected"; }?>>Regular User</option> <option value="3" <?php if($query['level']=="3") { echo "selected"; }?>>Donator</option> <option value="4" <?php if($query['level']=="4") { echo "selected"; }?>>Moderator</option> <option value="5" <?php if($query['level']=="5") { echo "selected"; }?>>Administrator</option> <option value="6" <?php if($query['level']=="6") { echo "selected"; }?>>Owner</option> </select> </td></tr> <tr><td class="first">User Avatar</td> <td><input type="file" name="photo"></td></tr> <tr><td class="first">Joined on</td> <td><input type="text" name="join" value="<?php echo date('d-F-Y',($query['join_date'])); ?>" disabled="disabled"></td></tr> <tr><td class="first">Last Access</td> <td><input type="text" name="access" value="" disabled="disabled"></td></tr> <tr><td></td> <td> <input type="submit" name="submit" value="Edit User"> </td></tr> </tbody></table> </form> <?php } ?> I am getting the error message "Couldn't fetch mysqli on line 48". Here's the script: By the way the uploading of the first file does work, but the upload of the second file so it updates and refreshes with a new avatar file name does not work. Code: [Select] <?php // This file gets included into profile_content.php // AVATAR code define ('AVATAR_UPLOADPATH', 'avatar/'); define ('AVATAR_MAXFILESIZE', '32768'); // _UPLOAD_ and _MOVE_ avatar to target location - START if (isset($_POST['submit'])) { $avatar = $_FILES['avatar_upload']['name']; $avatar_type = $_FILES['avatar_upload']['type']; $avatar_size = $_FILES['avatar_upload']['size']; // file type + file size + file upload + width & height VALIDATION if ((($avatar_type == 'image/gif') || ($avatar_type == 'image/jpeg') || ($avatar_type == 'image/pjeg') || ($avatar_type == 'image/png') && ($avatar_size > 0) && ($avatar_size <= AVATAR_MAXFILESIZE))) { if ($_FILES['avatar_upload']['error'] == 0) { list($width, $height, $type, $attr) = getimagesize($_FILES['avatar_upload']['tmp_name']); if ($width == 64 && $height == 64) { // UPLOAD + MOVE //////////////////////// HERE IS THE LINE ///////////////////////////////////////////// // Update the file name $query3 = "UPDATE user SET avatar = '$avatar' WHERE user_id = '$user_id'"; $row3 = mysqli_query ($dbc, $query3) or die (mysqli_error($dbc)); // Move the uploaded file on the disk to its folder move_uploaded_file ($_FILES['avatar_upload']['tmp_name'], $target . $avatar); // Rename the file into a more usable file name $avatar = rename($avatar, $user_name . '_' . rand(111111, 999999)); // Success echo "Your avatar has been successfully uploaded. Please refresh the page to see the changes."; // error messages // width and height error } else { echo "Your avatar has to have a width and height of 64 pixels, please crop it or use a different avatar."; } // file upload error } else { echo "Error: " . $_FILES['avatar_upload']['error']; } // file type error } else { echo "The avatar must be a GIF, JPEG or PNG image file and no greater than " . AVATAR_MAXFILESIZE / 1024 . " KB in size."; } } // END ?> Any ideas why I am getting the error message. I marked the corresponding line with ///// HERE IS THE LINE //// in the mid area. Hi ppl got code problem cant get it show users avatar & blank avatar at same time not that good at php ppl. avatar box page Code: [Select] <style type="text/css"> #name_area{height:20px; padding:3px;}; </style> <script language="javascript"> <!-- function member_change(id){ <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { ?> document.getElementById('<?php echo mysql_result($allgames, $i, 'game_id'); ?>').style.display = "none"; <?php $i++; } } ?> document.getElementById(id).style.display = "block"; } function show_name(name){ document.getElementById('name_area').innerHTML = name; } function hide_name(){ document.getElementById('name_area').innerHTML = ''; } //--> </script> <div style="text-align:left;"> Choose Squad: <select name="D1" onchange="member_change(this.options[this.selectedIndex].value)" class="standardforms"> <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { $game = mysql_result($allgames, $i, 'game_title'); $members_total2 = mysql_num_rows(mysql_query("SELECT * FROM members WHERE game = '$game'")); if($members_total2!=0) { ?> <option value="<?php echo mysql_result($allgames, $i, 'game_id'); ?>"><?php echo mysql_result($allgames, $i, 'game_title'); ?></option> <?php } $i++; } } ?> </select><br /><br /> </div> <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { $game = mysql_result($allgames, $i, 'game_title'); $members = mysql_query("SELECT * FROM members WHERE game = '$game'"); $members_total = @mysql_num_rows($members); if($allgames_total!=0) { ?> <div id="<?php echo mysql_result($allgames, $i, 'game_id'); ?>" style="display: block; text-align:left;"> <?php if($members_total!=0) { $d=0; while($d<$members_total) { ?> <a href="index.php?page=members&id=<?php echo mysql_result($members, $d, 'id'); ?>"><img onmouseover="show_name('<?php echo mysql_result($members, $d, 'username'); ?>')" onmouseout="hide_name()" src="user/<?php echo mysql_result($members, $d, 'avatar_link'); $filename = 'avatar_link'; if (file_exists($filename)) { echo "avatar_link"; } else { echo "avatars/blank.jpg"; } ?>" width="50" height="50" alt="<?php echo mysql_result($members, $d, 'username'); ?>" title="<?php echo mysql_result($members, $d, 'username'); ?>"/></a> <?php $d++; } } } echo "</div>"; $i++; } } ?> <div id="name_area"></div> Hi All, I have a table, the column type is an attribute that items in this table share. A simple explanation would be if the field was colour and the items could be one of the colours. I am struggling with a for each loop to get the items out of this table grouped by this value. I am wanting to create a dopdown where the item_type is a header. This is what i have so far which obviously doesnt work: unction getRentalItems($display){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(' SELECT i.id, item, it.type, price_GBP, price_USD, price_CAD FROM items i LEFT JOIN item_type it on i.type = it.id '); $stmt -> execute(); $stmt -> bind_result($id, $item, $type, $gbp, $usd, $cad); if($display == 'Options'){ $out = ''; while($stmt -> fetch()){ $out .= '<optgroup label="$type">'; $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; } } return $out; } I would like the optgroup to be first whenever the type changes. I hope this explanation makes sense - there is an image to show what i mean - the bold text should only appear once per instance. Edited October 10, 2020 by Adamhumbug Eventually I will have around 5 or 6 queries that will be replicated in several different pages, albeit with a slight difference in each (generally just a change in the WHERE part). I have been thinking about placing these common queries in a separate file and calling that file with an 'include' on the pages the query is needed. My two questions are.... Would this be more beneficial than place the query in the page itself and would there be any downside (as in loading times) if I placed all of these queries in one external file (ie. would this cause all the queries to load each time. Thanks in advance for any advice. Steve In my mysql database i have a field that records peoples details one part of the details is their county/region they live in. It records the county in a normal varchar field however i need a simple php script that searching the database and finds the most common county so i can then return to the screen where the most popular region for my members. Thank you for reading. I have wizard that asks several predefined questions to find-out user needs. at the end it must offer some items based on user answers. all of available items have some properties in common and one or two specific properties. what is the best way or algorithm to do this in JavaScript? e.g: Item 1 Properties: Name Weight Color Size Item 2 Properties: Name Size Weight Item 3 Properties: Name Color Size Thanks. Hello, I have two arrays: $questions, which has 'question_id' as one of its keys and $assignment_questions which is a subset of $questions, pulled off my database. Using php, I'd like to construct a 3rd array which takes my $questions array and removes from it any question that has a question_id which can be found in both $questions and $assignment_questions, in addition to the other values associated with a particular question_id. For example, $questions has: question_id, solution, author (and other keys). Is there any way to check if a particular key matches and then zap out all of the corresponding fields (solution, author, etc.)? Thanks! If I have three files such as the following, and put session_start() in each, the session cookie will be domain: "mydomain.com" and path "/". As such, the session will be shared between all three files.
http://mydomain.com/index.php http://mydomain.com/folder1/index.php http://mydomain.com/folder1/folder2/index.phpIf I want the cookie to be unique to each file, then it seems I have several options. I could use session_name() to give the cookie a unique name for each file. I could use session_set_cookie_params() to set a unique path for each (/, /folder1, /folder1/folder2), however, the index files in the children directories will also be sent the root directories session cookie, right? Will this cause problems? Should both approaches be implemented? Or is there another approach? Thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321735.0 Hi,
I have the following query
SELECT user_details.User_club_ID, user_details.fname, user_details.lname, user_details.email, user_details.club_No club.CLUBCODE, club.club_id FROM user_details, club WHERE club_id = $cid AND user_details.club_No = club.CLUBCODE AND user_status = 'active'";which I converted to a prepared statement as SELECT user_details.User_club_ID, user_details.fname, user_details.lname, user_details.email, user_details.club_No club.CLUBCODE, club.club_id FROM user_details, club WHERE club_id = ? AND user_details.club_No = club.CLUBCODE AND user_status = ?";Please note that user_status is a field in the table user_details. The original query (non -PDO) works correctly. I want to know if this is correct and that the comparison in the WHERE clause i.e. user_details.club_No = club.CLUBCODE is security safe. If not then how should this be modified. Also if there is a better way to write this statement, kindly show that as well. Thanks Thanks all ! Edited by ajoo, 11 December 2014 - 02:35 AM. I'm attempting to set up a script that will choose a "random" image from a directory and then place it in an article when it's posted. I currently have a php file that randomly assigns a picture on each refresh, however my employer wants the image to be static after posting. So I guess the short of my question is, what would be the best way to go about something like that or is it even doable with PhP. |