Fatal error: Call to undefined function sanitize() in general.php on line 5
This is general.php:
include"connect.php";
function user_id_from_username($username)
{
$username = sanitize($username); //This is line 5/general.php
return mysql_result(mysql_query("SELECT `id` FROM `users` WHERE `username`='$username'"),0, 'id');
}
connect.php contains my database connections, I have a confusion, do I need to include it in the function or functions will do it automatically connect to my database?
I am using the function in user.php As:
if(isset($_GET["username"])===true && empty($_GET["username"])===false)
{
$username = $_GET["username"];
$user_id = user_id_from_username($username);
echo"$user_id";
}
It means exactly what it says,
sanitizeisn’t defined in scope. It’s not a standard function so it should be somewhere within your code. You can most likely substitute it directly withmysql_real_escape_string.You should of course consider moving to
PDOand parameterized queries.