sql - PHP: Getting URL Referral Key -


I am working on the email referral link for user registration with PHP.

The idea is that when you register, a random string is generated as a url referrals and sent to your inbox. Then when you click on the link provided in the email, you are sent to the page that confirms your account.

Although I'm having problems getting the referral key from the URL and matching with DB. / P>

So far what I have:

  // Example URL - http: //example.come? Ref = 5493tgfd83 $ passkey = $ _GET ['ref']; $ Success = true; $ CheckKey = "SELECT * FROM $ tbl_name WHERE confirmCode = '$ passkey'"; $ ConfirmKey = mysql_query ($ checkKey); If ($ confirmKey) {$ countKey = mysql_num_rows ($ confirmKey); } // key does not match the redirect on 404 if ($ countKey! = 1) {header ("location: 404.php"); $ Success = false; }  

For the time being, the query is not running and the page is not redirecting as expected. That is, if I enter the wrong key, the page does not redirect. Here are two working examples: num_rows

Better results will be achieved using mysqli_ * functions with a prepared statement

   connect_errno> 0) {die ('connection failed ['. $ Db-> connect_apper. ']'); } // $ passkey = $ _GET ['ref']; $ Passkey = mysqli_real_escape_string ($ db, $ _GET ['ref']); $ Tbl_name = "yourtable"; // $ query = "SELECT * FROM $ tbl_name WHERE confirmCode =?"; $ Query = "SELECT confirmCode $ tbl_name WHERE confirmCode =?"; If ($ stmt = $ db- & gt; Ready ($ query)) {$ stmt- & gt; Dam_param ("s", $ passkey); If ($ stmt-> Execute ()) {$ stmt-> Store_salt (); If ($ stmt-> num_rows == 1) {resonant "code verified."; Go out; } Else {echo "sorry."; // Lower down and remove the echo / headers above ("HTTP / 1.1 404 not found"); // headers ("location: 404.php"); //    Go out; }}}  

Use the mysql_ * functions:

   

Footnotes:

mysql _ * Function Exclusion Notice:

< P>

This extension has been deprecated as PHP 5.5.0, and is not recommended to write new code because it will be deleted in the future, instead of using extensions or extensions should go. See also for more help when choosing a MySQL API.

These functions allow you to access MySQL database servers.

Documents for MySQL can be found on ».

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -