This topic is locked

I'm having trouble with a $sql snippets

9/10/2020 7:12:59 PM
PHPRunner General questions
S
skbrasil author

I'm having trouble with a $sql snippets
in my consultation it cannot run.
In this query the user id of the session instead of showing the id displays the email field eg user@gmail.com
in my sql query in my local test it worked but in the code snippet it doesn't work



$sql = "SELECT id AS aff_id FROM tblclients where email LIKE ".$_SESSION["UserID"];

$aff_id = CustomQuery($sql);

$data = db_fetch_array($aff_id);

echo"". $data["aff_id"];


php Ocorreu o erro...
Erro 626
Consulta de SQL SELECT id AS aff_id FROM tblclients where email LIKE user@gmail.com
the sql query



SELECT id FROM tblclients where email = 'user@gmail.com'
D
david22585 9/10/2020

Try this:

$sql = "SELECT id AS aff_id FROM tblclients where email LIKE ".$_SESSION["UserID"].";

$aff_id = CustomQuery($sql);

$data = db_fetch_array($aff_id);

echo"". $data["aff_id"];
S
skbrasil author 9/10/2020

Thanks for listening, but the code didn't work.
It will be if it has to do with my version of PHP 7.4

Sergey Kornilov admin 9/11/2020

There are several issues here:

  1. You are using LIKE instead of =
  2. You are missing single quotes around text values
    Here is the correct line of code:

$sql = "SELECT id AS aff_id FROM tblclients where email="'.$_SESSION["UserID"]."'";
S
skbrasil author 9/15/2020



There are several issues here:

  1. You are using LIKE instead of =
  2. You are missing single quotes around text values
    Here is the correct line of code:

$sql = "SELECT id AS aff_id FROM tblclients where email="'.$_SESSION["UserID"]."'";



I made this attempt, but the sql query above is not working.
My question is:
The user id that phprunner captures is the user table id or email.
in my case i have this difficulty because even after logging in the system instead of showing the user id as number is shown as email.
Since the system is configured to login via email and not with a username.

Sergey Kornilov admin 9/15/2020

$_SESSION["UserID"] will hold the value of the field that was selected as a username. Can be an email address or can be any other field.
You need to explain it further and provide more info. What error message you getting now?