PHP: sending a link to a results page - php

I am learning PHP:
A person will get a results page. I want to enable this person to be able to send the results page (via link) to their given email (form). The link won't be constant as the results page would be specific for that person/ possibly session?
The results page is simply a html script containing sequences that have been run through a prediction model.

Store the results in a database. Construct a php page that would fetch that data from the database according to a GET variable. Give a link with appropriate GET variables to the user.

The best way to do this would be to have the search terms in the URL itself.
For instance, if its one search term, it could very easily be:
http://www.yoursite.com/search.php?term=search+term
Just handle this in PHP as:
<?php
$term = $_GET['term'];
/* blah blah, process the search and echo results */
?>
You could even utilize paging, and put the page in the URL itself, so that when the person returns to the link, it brings them right back to where they emailed it from. The rest is up to you.

Related

Passing Variables between PHP pages then performing a MySQL search

fairly new to PHP and webdesign.... I have a website which has a bunch of products for vehicles - all of this is stored in a database.
In order to narrow down what products are available, I want to take the user through 2-3 pages where they firstly select what categorey of product they want, then what make of car they have, then the model, then I want to run a mysql query with that information and return the answerson a page.
I already have the code to request the info from a database and then display it on the page, but The way the current website is setup, they are hard coded mysql queries (meaning the user didnt input any data to get there).
So how can I transfer variable between php pages? Page 1 (contains Categorey) - then pass to Page 2 (contains Make) then page to Page 3 (contains Model) then compile the three variavles collections, and pass them to results.php (a standard results page which Gets variables and then searches).
I know this might seem basic, but I am really stumped as to how to get it coded.
If someone can give me an a newbie explanation about how to achieve this? Thank you
You can pass PHP variables through URLs for example
Your HTML code,
<a href='yourPage.php?yourVariable=someValue'>TEST!</a>
Your PHP code,
if (isset($_GET['yourVariable'])) {
$yourVariable = $_GET['yourVariable'];
// Your code here.
}
Now using this you can create what you want with a little bit of tinkering.
Remember
You need to use $_GET because parameters are being passed using the URL and not a POST request.
Don't forget to clean all input.

PHP MySQL auto-create hardcoded hyperlinks

Below is a picture of my database.
I am going to make the numbers on the left (81305, 81306, etc..) all hyperlinks.
When the user clicks on the hyperlink, they will be directed to a page (all links will be this page) "dpupage.php". This page will have a form with empty values. I will then use SQL queries (according to the NUM) to fill the form with the rest of the columns according to the number they picked.
The problem I have is that I will need to email users a specific link to their specific form.
But I can't set the url to, for example: http://mysite.com/dpupage.php because it will send them to a form with empty values. How can I create a link that will open up the dpupage.php and still query the data they need.
For example: Lets say I need a user to address NUM: 81309. An email is sent to them through phpmailer with a link. This link needs to take them directly to that dpupage.php and fill in all data that corresponds with NUM 81309.
Any advice is greatly appreciated!
Use PHP
Give them a link with a parameter, for example http://mysite.com/dpupage.php?num=12345
You can get the number they used via $_GET['num']. Get your values from your DB (example: "SELECT * FROM wahtever_your_table_is_called WHER NUM = $_GET['num']).
Paste the values into the field.
Beware: that's an easy example, don't do it that way! SQL-Injections will eat your dog! Google it!

How to sent parametres to url? get method for PHP?

how can I send PHP parametres, get method like .php?id=xx
I am using K2 items with Joomla. Currently I am printing out all results fetched from database using PHP. When user clicks on one of the results it should send him to different page and that page should get id of the thing user clicked. How do I do it if joomla shows me sites like:
joomla.com/index.php/example-showing-this/
This is a very broad question, and we'd more details to better help you. On a broad level, you can generate these URLs using PHP and JRoute http://docs.joomla.org/JRoute/1.5
You may also find this thread helpful too https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-general/1548yu9I2jQ
When the user is able to click on things this is no longer PHP, this is HTML and javascript. PHP is executed on the server, the result of this execution is the HTML+CSS+Javascript that the user downloads to its pc.
From what you descrived you need to generate the correct HTML+javascript using the PHP variables you get from the database, for example:
echo "Click me";
This will display a link, but it will not pass any parameters, if you want to pass a id using GET you should do it like this:
$id=1234;
echo "Click me";
In the your_php_page.php you can receive this id like this:
$id=$_GET['id'];
//if you are going to use this in a query you should do something like this to prevent injection
$id=$mysqli->real_escape_string($id);
If you want to use POST, you will have to submit a form or use AJAX, but that's more advanced, you should focus on making it work using GET.

Populating PHP page with MySQL info from a variable in the URL

I'm trying to create unique urls for user's of a site I'm designing. Basically I want the url to look like this:
http://www.example.com/page.php?user_id=3
Or whatever user_id they are assigned. Basically I want user to be able to go to that url and it generates the page with the info (first name, last name, etc.) of the user from the row in the MySQL table with that user id number. I know that creating the URL would be done by $_GET but this is sort of backwards from that. I want them to be able to go to the URL and the pages gets the variables from the URL.
Sorry if this is basic, I'm having trouble searching for an answer because it always gives me the answer on how to submit a form TO the URL not FROM the URL. Thanks for all the help.
$user_id = $_GET['user_id'];
you could use this to get the variable.And then search the database for the matching id and get get all the details.
Since you want to contain all the details in you form.You could keep adding the other elements like this.
http://www.example.com/page.php?user_id=3&first_name=Max&last_name=Payne
Using $_GET[which element you want the value of]
Accessing the get variables on the page is really simple!.In your case as you want to access the user id,you can get from $_GET['user_id'] and fire the respective query to fetch the user details to populate the page.For more reference you could check here
http://php.net/manual/en/reserved.variables.get.php

Paginator doens't store search parameters

i'm using jpinedo.webcindario.com/scripts/paginator at my search script, but when i click on the page 2 the parameters from the first search are lost (i get my own message for "you need to type at least 2 characters")
how can i make it work?
this is my search.php:
$q = mysql_real_escape_string($_POST['q']);
$option = mysql_real_escape_string($_POST['option']);
that are coming from my index.php, search module
(the rest are just the same from the script example, a simple search)
i tried:
$_pagi_propagar = array("q","option","search");
You want to make your search GET based instead of POST based. This is because clicking a link is always GET based, so it's easier to change the search submit to GET than change the links to POST, since that requires a fair bit of javascript.

Categories