PHP MySQL auto-create hardcoded hyperlinks - php

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!

Related

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

URL Query String to check database on Window Load

I am creating a mobile guest list for a party that I'm having in a few months. All of the invites that I am handing out will have a custom QR Code on them, embedding their first and last name. When they get to the party, they check in with me, I scan their QR Code and throw them into a database.
I have the core elements working where the custom QR Code with the embedded query strings for first and last names pre-populate a set of text inputs for the first and last names, you fill in some other information, click submit and BANG, you're in the database.
I would like to add some extra functionality that checks the database that someone has already checked in, to prevent party crashers.
What code would I need to write to allow, onWindowLoad, the first and last name query strings to be checked against the database to see if entries containing those already exist?
Thanks in advance
Ajax call with a select. Make it easy on yourself, use jQuery. Here are some examples:
Ajax Examples with jQuery

PHP: sending a link to a results page

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.

php report button

I am working on a search script and on each search result I want a report link button. I am not sure how to make one. I have looked on google for answers but cannot come up with anything. Can anyone give me an idea of what to do? or does anyone know where there is an example of this? I plan on using the link id and making a new table on mysql to send reports to. I am just looking for a basic button to send reports to mysql I am just not sure what would be the best way to do it. I have the data for the link id's I just need to be able to report it to a new table I am assuming. Any suggestions or examples are very appreciated. Thanks.
Chris,
First you will want to create that new table in your database to capture this information. Lets assume to you will have the following fields (very basic, you may want to add more): ReportId, LinkId, DateReported. ReportId is our primary key, LinkId is the ID you reference in your question and the DateReported is the server time we logged the transaction.
With this table created you are going to want to create a new php page, lets call it report-link.php. You are going to want to make this page accept a querystring variable called linkid (accessible in the $_GET[] collection). In the code of this page you will want to write a SQL query that inserts the value of the linkid parameter into the new link report table in the database (along with the date()).
On your search page you will be able to have users report an entry by clicking a link with the href of /path/to/report-link.php?linkid=<?php echo $link_id; ?>
Please note this example is very simplistic in nature, and offers no security for spamming, pleasant end user experience after they click the link, but this is the process you will want to follow in setting this feature up. After you have it working you can spruce up the experience for your users.

Extending URIs with 2 queries (i.e. 'viewauthorbooks.php?authorid=4' AND 'orderby=returndate") Possible?

I have a link in my system as displayed above; 'viewauthorbooks.php?authorid=4' which works fine and generates a page displaying the books only associated with the particular author. However I am implementing another feature where the user can sort the columns (return date, book name etc) and I am using the ORDER BY SQL clause. I have this also working as required for other pages, which do not already have another query in the URI. But for this particular page there is already a paramter returned in the URL, and I am having difficulty in extending it.
When the user clicks on the a table column title I'm getting an error, and the original author ID is being lost!!
This is the URI link I am trying to use:
<th>Return Date</th>
This is so that the data can be sorted in order of Return Date. When I run this; the author ID gets lost for some reason, also I want to know if I am using correct layout to have 2 parameters run in the address? Thanks.
Yes, the layout is correct. Of course it's possible to have even more than 2 parameters in the query string
you have to check resulting query string (just take look into your address bar after click), there must be something like viewauthorbooks.php?authorid=22&orderby=returndate. If number is lost, you have to check it's source - $row['authorid'] variable.
you have to use & and sanitize your output, but apart from that it's correct ;)

Categories