I have a URL and a code that will vary all the time (Ex: usuario/perfil/39
).
I used the following code to get this value from the URL:
$valor_id = $_SERVER['REQUEST_URI'];
$cod = explode("/",$valor_id);
$codigo = $cod[4];
So I need to use this code in a SELECT. I did so:
$sql = "SELECT tipo FROM users WHERE ID = " . $codigo;
And I had the following error:
Fatal error: Error executing query: SELECT type FROM users WHERE ID = - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server for the right syntax to use near '' at line 1 in C: \ xampp \ htdocs \ parties \ registry \ mysqldb.class.php online 243
When I do this:
$sql ="SELECT tipo FROM users WHERE ID = 36";
It works fine, so I believe the problem is in concatenating the variable in the query. Note: in BD, the type field is integer.
Part of the code that says the error occurs:
public function executeQuery( $queryStr )
{
if( !$result = $this->connections[$this->activeConnection]->query( $queryStr ) )
{
trigger_error('Error executing query: ' . $queryStr .' - '.$this->connections[$this->activeConnection]->error, E_USER_ERROR); //LINHA 243
}
else
{
$this->last = $result;
}
}