Users friends link not working - displaying 404 error - php

I'm in the process of creating a website that allows people to do quizzes about different topics and for the quizzes, I have a button called Ask A Friend. At the moment, with the code I have, it doesn't display anything to press and when I click on the area where the mouse changes to a pointer, I get shown a 404 error. What I want to happen is, is a user clicks on the button, it directs them to their own friends list.
The code that I have is:
<div class="AskAFriend">
<div class="askafriend">
<a href="<?php global $current_user; echo home_url() . '/members/' . $current_user->user_login . '/friends/'; ?>">
<input class="AskAFriend_button" name="askafriend" type="button" value="Ask A Friend For Help" />
</a>
</div>
</div>
When I had it with an empty <a> tag, it displayed a button as I wanted, but with the code I have now, no button gets displaed and I get directed to a page that has a 404 error on.
I believe that it's the <a> tag that's causing the trouble.

Alright, so I'm guessing the user is logged in, and that you save the user's ID in the session. What you can do is make a page like friends.php, on there using PHP you get the user ID from the session variable, once you have that, query for all the friends of that user. This way, you have one page that will be used by all the different users.

If you are using buddypress plugin, then may be it has some conflict with other plugin. It happened with me. In my case buddypress plugin conflict with upme plugin, you have to check it first.

Try:
<a href="<?php echo bp_loggedin_user_domain . '/friends/'; ?>">

Related

How to add button for every field when retrieving data from a database

I have looked everywhere for this question, perhaps I'm just not phrasing it correctly.
I have a page displaying various products, the table is called items. There in my fields I have all the information and images to display on the page, this works fine. Now I want to be able to press a button to add the item to cart, I have the code below where I access the data.
<div class="col-md-5">
<h2 style="font-size:25px;"> <?=$items['title'];?></h2>
<img src="<?=$items['image'];?> "width='300' height='500'/>
<p style="font-size:20px;" class = "lprice">GBP <?= $items['price'];?></p>
</div>
Now that I have done that, my question is how can I add a button for every time a result is displayed and have that button linked with that item, I appreciate this may no be as straight forward as I am phrasing this, but just looking for some help.
Thanks
You can do it in two ways, either way, you need a primary key (eg: id) in your items table which will hold a unique number for each of your items.
After that, you print your id along with everything else inside a button or inside an a tag. Like
<div class="col-md-5">
<h2 style="font-size:25px;"> <?=$items['title'];?></h2>
<img src="<?=$items['image'];?> "width='300' height='500'/>
<p style="font-size:20px;" class = "lprice">GBP <?= $items['price'];?></p>
<a class="btn btn-primary" href="add_to_cart.php?id=<?=$items['id'];?>">Add to Cart</a>
</div>
Now inside your add_to_cart.php file, you can receive the id of the products like this $product_id = $_GET['id'];
Once you have the id of the product, you can process the rest on the add_to_cart.php file and redirect the user back to the previous page with a success or error message.
This way, we passed the id using a URL parameter. The second way is to pass the id using a form. I just wanted to let you that this method exists. I hope this helps. If you have any doubt, feel free to ask in the comment section.

Link back to variable anchor on previous page?

I have a simple page. On this page, I have blocks. The blocks get their unique ids when clicked open (example: http://blog.com/#brands). The ids are variable:
<div class="block wide" id="<?php echo $postid ; ?>">
blog category
</div>
Someone clicks the link in the block & goes to the blog. Now the visitor is on the blog category page. But the visitor wants to go back to the homepage:
<span class="return-back">back</span>
But now, it is back to the top of the homepage. I want the visitor to be back at the variable id anchor of the blog:
<div class="block wide" id="<?php echo $postid ; ?>">
How do we make this happen? I am not a PHP developer (just CSS/JS/HTML). I've used Wordpress for this project. Thank you all so much!
The format for linking to a div through url is:
mypage.com/blog#blog_id
where blog_id is the id of the div you'd like to link to.
So, assuming $postid is the id of the div you want to link back to, try this:
back
This is actually impossible to solve without rebuilding everything. The next page doesn't know what $postid is.

Facebook connect login switch back to user breaks out of div

I've been trying to wrap my head around this for hours but I cannot figure it out. Usually I can find my answer by searching StackOverFlow but this time I'm truly stumped.
The "Login with Facebook" button works perfectly fine when logged in as a FB User. But when logged in as a FB Page, it gives the "switch back to xxxxx user to use this plugin", which is perfectly normal. However the blank/white part of this message breaks out of the div and covers up the other contents of my page!
The code is as follows:
<div id="LoginButton" style="margin-top:20px;width:130px;margin-left:auto;margin-right:auto;">
<?
if(!$fbuser) //Only show login button if user is not Logged In to FB
{
echo '<div class="fb-login-button" onlogin="javascript:CallAfterLogin();" size="small" scope="email">Login w/ Facebook</div><div class="clear"></div>';
}
else
{
//process user as a FB user
}
?>
</div>
I've tried:
clearing the div, which doesn't seem to matter
testing with just plain text inside fb-login-button, which parent div
LoginButton seems to contain fine
replacing fb-login-button code with rendered code from Facebook JS
API, but then the button is not clickable anymore
You can see the problem present if you surf the website http://www.dealshongkong.com as a FB page (you can see it happen on the left hand side of the page).
I've attached a pic here of what I see when logged in as FB Page (the problem):
http://www.dealshongkong.com/temp/stackoverflowproblem.jpg
I experienced the very same problem. I found no other way arround than to use a custom Facebook Login Button. I just built a PNG file and added some Facebook JavaScript API call.
<div id="FaceBookLoginButton" onclick="FB.login(function(response) { },
{scope: \'email\'});"
style="background-image:url(/buttons/my_own_facebook_login_button.png);"
/>
<span>Log in</span>
</div>
It works fine for the login button. But in case you want to use other social plug-ins (Like-Button, Like-Box, Send-Button, ...) you will experience the same problem again.

contact form including referral of previous page button (multiple on one page)

I asked a similar question over here (http://stackoverflow.com/questions/13856915/contact-form-including-referral-of-previous-page).
"I have a php contact form using POST and I want to automatically include the referring page on the form, that is the website linking to the contact form. This would normally be within my website." I now have HTTP_REFERER working fine on my contact form to show the previous page link.
My next step is to have the same/similar result, but the referring page has a number of tours listed on the same page, so just including the URL isn't enough. I want to know which link/button they clicked to find the contact form.
Here is an example:
On tours.php I have the following code (multiple times on the same page):
<a href="<?php echo($domain); ?>/contact/booknow.php" </a>
I could change that to:
<a href="<?php echo($domain); ?>/contact/booknow.php?tourname" </a>
<a href="<?php echo($domain); ?>/contact/booknow.php?tourname2" </a>
On the contact form I want to store that they came from tours.php and tourname2, etc.
So how can I store that information on the contact form, so I know which button they clicked on (which tour they are interested in)?
Or do I need to add another variable in the link on the tour.php page?
Many thanks,
Andy
booknow.php?tourname1
booknow.php?tourname2
booknow.php?tourname3
When clicked, your next page will have access to $_GET['tourname1'] or $_GET['tourname2'] or $_GET['tourname3'] so you can test if they exists and you'll know on which link your visitor clicked.
I would suggest to change a bit for something like this :
booknow.php?tourname=1
booknow.php?tourname=2
booknow.php?tourname=3
So you can check if "tourname" exist and if so get its value "$_GET['tourname']".
Here you go :
$ref_url = $_SERVER['HTTP_REFERER'];
$ref_link = 0;
if( isset($_GET['tourname']) ) {
$ref_link = $_GET['tourname'];
}

Tracking purchases via dynamic button that redirects to outbound links

I need to track purchases on my site via a dynamic button that redirects to another sites.
The code:
<div class="buyproduct">
<a onclick="target='_blank'" href="<?php echo $this->product['from'];?>">
<img src="http://xxx.com/data/images/buy.jpg" alt="Buy!"/>
</a>
</div>
Everytime a user clicks on the button it redirects to another site outside mine.
For example if I click on a jeans and then in the buy button, it redirects to wrangler site.
I need to track everytime this happens and know exactly to what url the user is beeing redirected.
The site is in PHP and Javascript.
You could create an intermediate page on your server, maybe something like (out.php). You could then redirect all traffic to the out.php page, do the processing there, and then redirect.
<a target="_blank" href="/out.php?url=<?php echo urlencode($this->product['from'])?>">
<img src="http://xxx.com/data/images/buy.jpg" alt="Buy!"/>
</a>
out.php
<?php
$url = urldecode($_GET['url']);
/*
MySQL CODE TO PROCESS TRACKING
*/
header("Location: ".$url);
exit;?>

Categories