Haruo Posted June 21, 2009 Share Posted June 21, 2009 Hi, I found a great PHP membership system on BioRust.com here is a URL for it http://www.biorust.com/tutorials/detail/115/en/ But what i wish to add is ability for my members to upload avatars. Here is what I coded but it dosent work some help... process.php add-on if(isset($_POST['changeavatar'])) { $current = trim($_POST['current']); $new = trim($_POST['new']); $query = mysql_query("SELECT * FROM Users WHERE avatar = '$current' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($query) > 0) { while($row = mysql_fetch_array($query)) $do = mysql_query("UPDATE Users SET avatar = '$new' WHERE avatar = '$current' LIMIT 1") or die(mysql_error()); if($do) { echo '<script>alert("Thanks, your avatar has been changed.");</script>'; echo '<script>location.replace("member.php?NC=avatar");</script>'; exit; } else { echo '<script>alert("There appears to have been an error in the script. Please try again or contact an admin.");</script>'; echo '<script>location.replace("logout.php");</script>'; exit; } } } and here what goes into member.php case 'avatar': echo ' <form action="'.$_SERVER['PHP_SELF'].'" method="post"> Current avatar:<br> <img src="'.$current.'" width="100" height="100" alt=".$_SESSION['s_username'].'" title="'.$_SESSION['s_username'].'" /><br> New avatar <input name="new" type="text" class="textBox"> <p><input type="submit" value="Change avatar" name="changeavatar"></p> </form> '; break; but when i enter URL for new avatar it dosent change avatar field in database neigher dose the script echo the avatar.. MySQL Tables for Users id int(11) No auto_increment Browse distinct values Change Drop Primary Unique Index Fulltext Username text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Password varchar(32) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Name text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Email text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Date text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext IP text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Actkey varchar(40) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Activated int(1) No 0 Browse distinct values Change Drop Primary Unique Index Fulltext avatar text latin1_swedish_ci No Please help me with this... Link to comment https://forums.phpfreaks.com/topic/163089-php-avatar-upload/ Share on other sites More sharing options...
Haruo Posted June 21, 2009 Author Share Posted June 21, 2009 Okay it add's avatar URL to the MySQL Talble Users "ROW" avatar But on the main page $current fails to display it... Link to comment https://forums.phpfreaks.com/topic/163089-php-avatar-upload/#findComment-860500 Share on other sites More sharing options...
Haruo Posted June 23, 2009 Author Share Posted June 23, 2009 bump.... Link to comment https://forums.phpfreaks.com/topic/163089-php-avatar-upload/#findComment-861622 Share on other sites More sharing options...
EchoFool Posted June 23, 2009 Share Posted June 23, 2009 Echo $current and tell me what it shows Link to comment https://forums.phpfreaks.com/topic/163089-php-avatar-upload/#findComment-861627 Share on other sites More sharing options...
Haruo Posted June 23, 2009 Author Share Posted June 23, 2009 I am sure echo "$avatar"; would work but here is the problem take a closer look on how the codeing is constructed <?php switch($_GET['NC']){ case 'avatar': echo ' <form action="'.$_SERVER['PHP_SELF'].'" method="post"> Current avatar:<br> $avatar New avatar: <input name="new" type="text" class="textBox"> <p><input type="submit" value="Change avatar" name="changeavatar"></p> </form> '; break; if i try <img src="'.$_GET['$avatar'].'" width="100" height="100" alt="'.$_SESSION['s_username'].'" title="'.$_SESSION['s_username'].'" /> It will show where the image has to be but it will be blank and all it will say is the users username... Also when I try to update the avatar via URL it dosent update, but if i remove the current recorded avatar URL in MySQL and input a new URL then it updates to the new avatar, the only extra thing i can think of is add this line to process.php if(isset($_POST['changeavatar'])) { $avatar = trim($_POST['avatar']); $new = trim($_POST['new']); $delete = trim($_POST['delete']); $query = mysql_query("SELECT * FROM Users WHERE avatar = '$avatar' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($query) > 0) { while($row = mysql_fetch_array($query)) $do = mysql_query("UPDATE Users SET avatar = '$new' WHERE avatar = '$avatar'") or die(mysql_error()); if($do) { echo '<script>alert("Thanks, your avatar has been changed.");</script>'; echo '<script>location.replace("member.php?NC=avatar");</script>'; if(mysql_num_rows($query) > 0) { while($row = mysql_fetch_array($query)) $del = mysql_query("DELETE avatar = '$new' FROM Users WHERE avatar = '$avatar'") or die(mysql_error()); if($del) { echo '<script>alert("Thanks, your has been removed.");</script>'; echo '<script>location.replace("member.php?NC=avatar");</script>'; exit; } else { echo '<script>alert("There appears to have been an error in the script. Please try again or contact an admin.");</script>'; echo '<script>location.replace("logout.php");</script>'; exit; } } } ?> Link to comment https://forums.phpfreaks.com/topic/163089-php-avatar-upload/#findComment-862054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.