Jump to content

Recommended Posts

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>

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

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.

 

 

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; 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.