How to Get POST ID from one page to another page - php

I have created a message system in wordpress. There s a consultation page fr each user.also a sidebar with certain menus. when the submit button is clicked the admin reviews the question and answers it. The message will be shown in the inbox sidebar menu on the same consultation page.
but whtever i tried am not getting the reply message of the corresponding user. my problem is that when i defined the link for inbox there is no id being passed.later in tht particular page whtever id s am calling its bring up the page id only and nothing else.
This is the sidebar code:
<li>
<i class="fa fa-sort-alpha-asc " aria-hidden="true"> </i> <span style="margin-left:10px;">Inbox</span>
</li>
now its bringing the id = 1. no matter which user it is.
this is the inbox code:
<?php
global $post;
$idd= $post->ID;
$title= $post->post_title;
var_dump($title);
echo "<div class= 'col-lg-4'><table style='width:500px;'><tr><td><b>Reply:</b> ".get_post_meta( $idd, 'docreply', true)."</td></tr></div>";
echo "<div class= 'col-lg-4'><table style='width:500px;'><tr><td><b>Amount:</b> ".get_post_meta( $idd, 'amount', true)."</td></tr></div>";

you can get the post id by using get_the_ID() function.
<?php
echo get_the_ID();
?>

Where is the message data saved?
I see you calling the page URL with the ID of the currently logged user.
Later, you're using the ID of the page then fetching two meta values and displaying them.
If you're using post meta, use the ID of the user that is logged in and get the meta value by using get_user_meta - https://codex.wordpress.org/Function_Reference/get_user_meta
More code would help solve this easier :)

Finally i have found a solution to my problem. I updated the post_meta values in to my user_meta and in the page where i need to display the data, i called the current user id and called the user_meta

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.

How do i get make session id from a loop of mysqli?

I am learning php and i need some help in one of my project.
How can i get id of a specific row while displaying the value of other column (in my case title) from a loop so that i can make it $SESSION and forward it to next page.
For now what i want to do is get an id of the row when i click the title and show the post in the next page and work further on it. I think i can use javascript for but don't know how to do so.
My codes (by which i am currently fetching data from database)
<div class="list-group">
<?php while($row = mysqli_fetch_array($search_result)):?>
<?php echo $row['title'];?>
<?php endwhile;?>
</div>
Thanks in Advance
Assume view_page.php is the page you want to view content of that row on when you click the row and you will use get method to extract id to go fetch content of a specific row in your database.
" class="list-group-item list-group-item-action list-group-item-dark">
on url address you will see something like after view_page.php?id=1
use this coode to get that row id: $id = $_GET['id'];

Users friends link not working - displaying 404 error

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/'; ?>">

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.

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'];
}

Categories