justlukeyou Posted December 15, 2012 Share Posted December 15, 2012 Hi, I have a form which inserts the users ID into 'follow' when they submit a form. However I am now trying to change it so the value of the ID is applied to an image. When the user clicks an image their ID is added to the database. Sounds tricky, can anyone advise how to do this please? <?php if(isset($_POST['followform'])) { $follow = $_POST['follow']; $query_follow ="UPDATE users SET follow = '".$_POST['follow']."'" ; $result_newUser = mysql_query($query_follow); $result = mysql_query($query_follow) or die("An error occurred ".mysql_error()); } ?> </div> <form class="followform" method="POST" action=""> <div class="forminputcell"> <div class="datainput"> <div class="forminputleft"> Follow: </div> <div class="forminputright"> <input name="follow" type="text" width="10" value="<?php echo $row['id']; ?>" /> </div> </div> <div class="user-area"> <input type="hidden" name="followform" value="submit" /> <input type="submit" name="submit" value="Submit" class="submit-button" /> </div> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/ Share on other sites More sharing options...
Pikachu2000 Posted December 15, 2012 Share Posted December 15, 2012 Do it the same way, except make the image the link instead of the text. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399536 Share on other sites More sharing options...
justlukeyou Posted December 15, 2012 Author Share Posted December 15, 2012 Thanks, But Im not sure how to do this. Do I put an image inside a form? How do I set the value of the an image to the ID. I haven't used this process before. Ive tried Googling the issue but all I can find is how to upload an image. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399541 Share on other sites More sharing options...
Jessica Posted December 15, 2012 Share Posted December 15, 2012 I don't believe that you even tried searching google. "image as form submit button" turns up plenty of useful results. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399542 Share on other sites More sharing options...
Jessica Posted December 15, 2012 Share Posted December 15, 2012 I don't believe that you even tried searching google. "image as form submit button" turns up plenty of useful results. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399543 Share on other sites More sharing options...
justlukeyou Posted December 15, 2012 Author Share Posted December 15, 2012 Thanks, I dont know I had to merge the submit button with the submit function! So is the key to this changing the name in the submit button? <input type="submit" [b]name="submit"[/b] value="Submit" class="submit-button" /> <input type="submit" name="<?php echo $row['id']; ?>" value="Submit" class="submit-button" /> Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399548 Share on other sites More sharing options...
justlukeyou Posted December 15, 2012 Author Share Posted December 15, 2012 All the examples I cant find involve changing the submit button on a form. With this I dont have a form. Do I just put the image inside the form and apply the ID to the image? Whenever I try a form it creates a form box which I dont want. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399555 Share on other sites More sharing options...
Jessica Posted December 15, 2012 Share Posted December 15, 2012 All the examples I cant find involve changing the submit button on a form. With this I dont have a form. Do I just put the image inside the form and apply the ID to the image? Hi, I have a form which inserts the users ID into 'follow' when they submit a form. However I am now trying to change it so the value of the ID is applied to an image. When the user clicks an image their ID is added to the database. Why do you smoke crack? Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399558 Share on other sites More sharing options...
Pikachu2000 Posted December 15, 2012 Share Posted December 15, 2012 http://bit.ly/QZP7vP Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399560 Share on other sites More sharing options...
justlukeyou Posted December 15, 2012 Author Share Posted December 15, 2012 (edited) http://bit.ly/QZP7vP But how do apply the ID number to the image and then insert the ID number into the database. These just show how to add a link to an image. Edited December 15, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399563 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 HI, Any suggestions please. I currently have it like this. If I use a type test it works but I would like to do it with an image. <?php if(isset($_POST['followform'])) { $follow = $_POST['follow']; $query_follow ="UPDATE users SET follow = '".$_POST['follow']."'" ; $result_newUser = mysql_query($query_follow); $result = mysql_query($query_follow) or die("An error occurred ".mysql_error()); } ?> </div> <form class="followform" method="POST" action=""> <div class="forminputcell"> <div class="datainput"> <div class="forminputleft"> Follow: </div> <div class="forminputright"> <input type="image" img src="/images/logo.png" name="follow" value="<?php echo $row['id']; ?>" class="submit-button" /> </div> </div> </div> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399830 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 There's no point in you asking another question until you turn on error reporting and post the errors, like you've been repeatedly told to do, yet for some reason seem to refuse. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399836 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 Point taken, do I need to add this to my .htm file? ini_set('error_reporting', E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399837 Share on other sites More sharing options...
mrMarcus Posted December 17, 2012 Share Posted December 17, 2012 You haven't explained your issue very well. Something you need to work on since you ask a lot of questions. Below is my interpretation of what you're looking for. Could be right, could be wrong... as I don't know what it is you're after, exactly. <?php if (($_GET['do'] == 'follow') && !empty($_GET['id'])) { $follow = (int)$_GET['id']; $query_follow ="UPDATE users SET follow = '". $follow ."'" ; $result_newUser = mysql_query($query_follow); //$result = mysql_query($query_follow) or die("An error occurred " . mysql_error()); // why are you hitting this twice? } ?> </div> <div class="forminputcell"> <div class="datainput"> <div class="forminputleft"> Follow: </div> <div class="forminputright"> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?do=follow&id=<?php echo $row['id']; ?>"><img src="/images/logo.png" class="submit-button"/></a> </div> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399838 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 (edited) Yep weldone mate for understanding me! I could do it with a for an submit button but not with an image.Im basically trying to create a follow button. Edited December 17, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399841 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 I notice that I can change the follower id in the link. So I can change the ID from 323 to 324. To stop this do I just amend the HT Access file so this information is not visible? followtest.php?do=follow&id=324 Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399843 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 No. There's no point in doing that. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399844 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 So how would I stop someone from saying that someone wants to follow someone when then dont want to? Currently I can make 321 follow 456 when 321 did not click the follow button. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399845 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 By validating that the user submitting the follow is logged in, and using their id. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399848 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 Hi, I have added this the HT Access file but it creates an internal server error. Does anyone know why this is please? ini_set('display_errors',1); Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399849 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 By validating that the user submitting the follow is logged in, and using their id. So it will only accept the logged in users ID? Sounds fine. I shall give that a go. I need to change it so that I can view another users profile and follow them. Currently it only allows my to follow myself but its getting there. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399851 Share on other sites More sharing options...
mrMarcus Posted December 17, 2012 Share Posted December 17, 2012 So how would I stop someone from saying that someone wants to follow someone when then dont want to? Currently I can make 321 follow 456 when 321 did not click the follow button. Your query should not execute unless the ID of the user is checked against the ID they are logged in as. That way, the URL cannot be modified for malicious activity. E.g. 1. User must be logged in to follow somebody. 2. When user clicks 'follow' button/link, have a condition that checks that the user who clicked the follow button is the same user who is logged in, ie. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?do=follow&id=<?php echo $row['id']; ?>¤t_user_id=12345"><img src="/images/logo.png" class="submit-button"/></a> 3. if (($_GET['do'] == 'follow') && !empty($_GET['id'])) { // check if user is logged in if (($_SESSION['auth']) && !empty($_SESSION['current_user_id'])) { // whatever your $_SESSION variables are for logged in users if ($_SESSION['current_user_id'] == $_GET['current_user_id']) { // again, $_SESSION['current_user_id'] is pseudo $follow = (int)$_GET['id']; $query_follow ="UPDATE users SET follow = '". $follow ."'" ; $result_newUser = mysql_query($query_follow); //$result = mysql_query($query_follow) or die("An error occurred " . mysql_error()); // why are you hitting this twice? } } } Your initial logic is out of whack. How you are currently storing follows (in the users table) is no good. It limits a users to only being able to follow a single user. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399852 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 Google "php error reporting". Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399853 Share on other sites More sharing options...
mrMarcus Posted December 17, 2012 Share Posted December 17, 2012 Hi, I have added this the HT Access file but it creates an internal server error. Does anyone know why this is please? ini_set('display_errors',1); .htaccess has nothing to do with this. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399854 Share on other sites More sharing options...
justlukeyou Posted December 17, 2012 Author Share Posted December 17, 2012 Hi, The plan is that User 123 can insert there ID into the follow row of User 456. Is that how its done? Currently it only lets User 123 follow 123 but its getting there. Quote Link to comment https://forums.phpfreaks.com/topic/272027-click-image-insert-into-database/#findComment-1399856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.