justlukeyou Posted February 17, 2013 Share Posted February 17, 2013 Hi, I am trying to complete a social networking button but I just cant sort one last peice of out. When I remove the following piece of code the social networking button works just by visiting the page. Does anyone have any suggestions on how I can get this peice of working. To be totally honest I dont even know what its supposed to be doing. The concept is to only run when the button is pressed. Am I making it to complicated? if(isset($_POST['followbutton']) && $_POST['followbutton'] == 'true'){ <?php $followerid = intval($_SESSION['userID']); $profileid = intval($row['id']); if(isset($_POST['followbutton']) && $_POST['followbutton'] == 'true'){ if($profileid = $followerid) { $errors['profileid'] = "This is a test error."; } if(!$errors){ //Validation of input vars passed, attempt to run query //Force vars to be ints to be safe for query statement $followerid = intval($_SESSION['userID']); $profileid = intval($row['id']); $query = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('{$profileid}', '{$followerid}')"; $result = mysql_query($query); if (!$result) { $errors[] = "Query: {$query}<br>Error: " . mysql_error(); } } } ?> <?php if($errors['profileid']) print '<div class="invalid">' . $errors['profileid'] . ''; ?> </div> <div class="followbuttonbox"> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?ID=<?php echo $profileid; ?>"><img src="/images/follow.png" id="followbutton" /></a> <input type="hidden" id="followbutton" name="followbutton" value="true"> <submit button> </form> Link to comment https://forums.phpfreaks.com/topic/274606-finish-final-stage-of-social-networking-button/ Share on other sites More sharing options...
denno020 Posted February 17, 2013 Share Posted February 17, 2013 I can't see an opening <form> tag? That omission of that will be halting anything coming through $_POST with your current code. As for what the code is doing: isset($_POST['followbutton']) - checks to see if the variable is set (which at the moment it probably isn't getting set without the opening form tag $_POST['followbutton'] == 'true' - makes sure the value of followbutton is true, but will only check this condition if the first condition is satisfied. Hope that helps, Denno Link to comment https://forums.phpfreaks.com/topic/274606-finish-final-stage-of-social-networking-button/#findComment-1413020 Share on other sites More sharing options...
justlukeyou Posted February 17, 2013 Author Share Posted February 17, 2013 Hi, The form starting here. Should I starting it here? <form action="" method="post"> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?ID=<?php echo $profileid; ?>"><img src="/images/follow.png" /></a> <input type="hidden" id="followbutton" name="followbutton" value="true"> </form> When I echo 'profileid' and 'followerid' I get the two different ID number which Im expecting but I just cant seem to insert them into the database when the button is pressed. Link to comment https://forums.phpfreaks.com/topic/274606-finish-final-stage-of-social-networking-button/#findComment-1413022 Share on other sites More sharing options...
PaulRyan Posted February 17, 2013 Share Posted February 17, 2013 This: if($profileid = $followerid) { Should be: if($profileid == $followerid) { Link to comment https://forums.phpfreaks.com/topic/274606-finish-final-stage-of-social-networking-button/#findComment-1413024 Share on other sites More sharing options...
justlukeyou Posted February 18, 2013 Author Share Posted February 18, 2013 Thanks, I changed that but it has had no affect. I have tried to echo the two ID numbers in different places. The thing is the second set of ID numbers do not echo. I cant understand why though as the third set do echo. Any suggestions please why this may be? echo $profileid; echo $followerid; if(isset($_POST['followbutton']) && $_POST['followbutton'] == 'true'){ echo $profileid; THIS DOES NOT ECHO echo $followerid; THIS DOES NOT ECHO $query = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('{$profileid}', '{$followerid}')"; $result = mysql_query($query); if (!$result) { $errors[] = "Query: {$query}<br>Error: " . mysql_error(); } } echo $profileid; echo $followerid; Link to comment https://forums.phpfreaks.com/topic/274606-finish-final-stage-of-social-networking-button/#findComment-1413185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.