-1

I'm trying to get values ​​from the database depending on the url. So, in my db I have a column with a keystring that is a unique number that I am generating, what I want to do is: From the URL, like "example.com/?keystring=dss76da1" I can get the column value 'email' associated with this keystring and use it in the current page with a variable. My sql table

I started the code that way but I don't know if it's right.

(URL: example.com/?keystring=dss76da1):

<?php

$key = intval($_GET['keystring']);
$results = mysql_query("SELECT * FROM users WHERE keystring='".mysql_real_escape_string($key)."'");    
while ($row = mysql_fetch_array($results))  

What should I do to get the value of the email column that is associated with the keystring and put it in a variable? So I can use on the current page..

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • Out of curiodity: have you tried to follow any recent tutorisls or books before asking a question? Just because this topic is covered by hundreds of those already! – Shadow Dec 28 '20 at 14:42
  • **Warning:** `mysql_*` extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0. Instead, either the [mysqli](https://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](https://www.php.net/manual/en/book.pdo.php) extension should be used. See also the [MySQL API Overview](https://www.php.net/manual/en/mysqlinfo.api.choosing.php) for further help while choosing a MySQL API. – Dharman Dec 28 '20 at 14:42
  • You need to use PDO and parameter binding. Please do some research. This code will not work and it's not very clear what your problem is other than using non-existent functions. – Dharman Dec 28 '20 at 14:44
  • Thanks guys, what type of tutorials should i study to be able to do this? – Silva Freitas Dec 28 '20 at 15:18
  • If you are only starting to learn PHP then you can start learning PDO instead here https://phpdelusions.net/pdo – Dharman Dec 28 '20 at 15:18

1 Answers1

-2
    <?php
$key = $_GET['keystring'];
$results = mysql_query("SELECT * FROM users WHERE keystring='".mysql_real_escape_string($key)."'");    
while ($row = mysql_fetch_array($results)) {
}
?>
Zoheib Ali
  • 21
  • 3