3
I have a URL and in it a code that will vary all the time (Ex: usuario/perfil/39
).
I used the following code to get this URL value:
$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 made the following mistake:
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 version for the right syntax to use near '' at line 1 in C: xampp htdocs festas Registry mysqldb.class.php on line 243
When I do that:
$sql ="SELECT tipo FROM users WHERE ID = 36";
It works right, so I believe the problem lies 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;
}
}
Why did you use 4? You really want the 5th item separated by the bars?
[0]/[1]usuario/[2]perfil/[3]39
– Bacco