so my code is this..
$password=(!isset($_POST['password']));
$username=(!isset($_POST['username']));
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$query = mysql_query ("SELECT * FROM tb_funcionario WHERE username='$username' and password='$password'");
$result = mysql_query($query);
var_dump($result);
$num_rows = $result->$num_rows;
if ($num_rows)
{
echo "username already exist";
}
else
{
$query = "INSERT INTO tb_funcionario (nome_funcionario, username, password) VALUES (
'$_POST[nome_funcionario]',
'$_POST[username]',
'$_POST[password]'
)";;
$result = mysql_query($query) or die (mysql_error());
}
mysql_query($query);
mysql_close($bd_con);
?>
And its always giving me the "mysql_query() expects parameter 1 to be string, resource given" and i cant figure out how to solve it.
Can yall help me?
解决方案
This is your problem:
$query = mysql_query ("SELECT * FROM tb_funcionario WHERE username='$username' and password='$password'");
$result = mysql_query($query);
You're running a query on the first line, which returns a "resource" as a result of the query. Then on the immediate next line you try to use that resource as another query to run again. You don't need the second line, the $result can be set in the first line.