jacko_162 Posted April 5, 2010 Share Posted April 5, 2010 Is there any code snippets out there to allow a user to select a an avatar from a table with a checkbox next to each, upon hitting submit button it adds the information of the avatar ID to a database, so i can call the image in various queries? i want a table with about 10 avatars (set by me!) and a user can select ONLY 1. any help on how i can do this would be great. im still learning PHP so go easy on me Link to comment https://forums.phpfreaks.com/topic/197669-allow-users-to-select-avatar/ Share on other sites More sharing options...
Jax2 Posted April 5, 2010 Share Posted April 5, 2010 Would be the same as anything else I'd assume... give each checkbox the same name, set the value of each one to the image url, or name, however you have it stored in the database, and then use a submit form at the end. They check one, submit the form and it add's the value of the one they checked as $image or $avatar or whatever. Link to comment https://forums.phpfreaks.com/topic/197669-allow-users-to-select-avatar/#findComment-1037375 Share on other sites More sharing options...
jacko_162 Posted April 5, 2010 Author Share Posted April 5, 2010 it was actually easier than i thought. can you check over my form please? for some reason its not updating the database with the value, when submitted. and also anyway to already check the box which the user already has selected in the database? <form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <?php if (isset($submit)) { // UPDATE QUERY CODE WHEN SUBMIT IS ENTERED $insert = "UPDATE members SET avatar='$avatar' WHERE member_id='$_SESSION[sESS_MEMBER_ID]'"; if (@mysql_query($insert)) { ?> <script type="text/javascript"> document.location.replace('index.php'); </script> <?php } else { echo('Error in you submission:' . mysql_error() . "<br /><br />" . $sql); } } ?> <br /> <table border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td><img src="img/avatars/avatar001.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar001" name="avatar"></td> <td><img src="img/avatars/avatar006.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar006" name="avatar" /></td> <td><img src="img/avatars/avatar011.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar011" name="avatar" /></td> </tr> <tr> <td><img src="img/avatars/avatar002.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar002" name="avatar" /></td> <td><img src="img/avatars/avatar007.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar007" name="avatar" /></td> <td><img src="img/avatars/avatar012.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar012" name="avatar" /></td> </tr> <tr> <td><img src="img/avatars/avatar003.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar003" name="avatar" /></td> <td><img src="img/avatars/avatar008.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar008" name="avatar" /></td> <td> </td> <td> </td> </tr> <tr> <td><img src="img/avatars/avatar004.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar004" name="avatar" /></td> <td><img src="img/avatars/avatar009.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar009" name="avatar" /></td> <td> </td> <td> </td> </tr> <tr> <td><img src="img/avatars/avatar005.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar005" name="avatar" /></td> <td><img src="img/avatars/avatar010.png" alt="" width="16" height="16" /></td> <td><input type="radio" value="avatar010" name="avatar" /></td> <td> </td> <td> </td> </tr> </table> <br /> <table border="0" cellspacing="0" cellpadding="8"> <tr> <td><input class="Button" type="submit" name="submit" value="Submit" /></td> <td><input class="Button-alt" type="reset" name="reset" value="Reset" /></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/197669-allow-users-to-select-avatar/#findComment-1037388 Share on other sites More sharing options...
Jax2 Posted April 6, 2010 Share Posted April 6, 2010 Well, you have one major problem ... you're not calling the variable "Avatar" in your isset function. It's then assuming avatar is blank... <?php if (isset($submit)) { $avatar=$_POST['avatar']; $insert = "UPDATE members SET avatar='$avatar' WHERE member_id='$_SESSION[sESS_MEMBER_ID]'"; if (@mysql_query($insert)) { ?> <script type="text/javascript"> document.location.replace('index.php'); </script> <?php } else { echo('Error in you submission:' . mysql_error() . "<br /><br />" . $sql); } } ?> <form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> ...etc That should work. Link to comment https://forums.phpfreaks.com/topic/197669-allow-users-to-select-avatar/#findComment-1037676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.