In the following main code:
Code: Select all
<html>
<body>
<form action="index3.php?login=yes" method="POST">
Username:<input type="text" name="user"><br />
Password:<input type="password" name="pass" ><br/>
<input type="submit" name="login" value="SIGN-IN" ><p>
</form>
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
$login=$_POST['login'];
echo $login;
function denied()
{
echo '<h3><span style= "color:red"> Access Denied!!! </span></h3><br><br>';
}
function granted ($user)
{
echo '<h3><span style= "color:green"> Access Granted!!! </span></h3>';
echo 'Welcome, ' . $user;
}
if($login=='SIGN-IN')
{
$con= include_once "mysql_connect.php";
$get = mysql_query("SELECT count(id) FROM login WHERE user='$user' and pass='$pass'");
$result = mysql_result($get, 0);
if (empty($user) || empty($pass))
{
//stop execution of PHP script using die function!
denied();
die("<br>Please fill out user login fields carefully....<br>");
}
if ($result!=1)
{
granted($user);
}
else
{
denied ();
//$_SESSION['user']=$user;
}
}
?>
</body>
</html>
Code: Select all
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "rhianna";
$db_name = "signin";
@mysql_connect("$db_host", "$db_username", "$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No $db_name Database ");
?>
I Think the problem lies with in mysql_result() function of the main script when using the $get variable as one of its parameters, but have absolutely no idea what it could be or how it can be fixed:Warning: mysql_result() expects parameter 1 to be resource, string given in C:\xampp\htdocs\index3.php on line 44
Code: Select all
$get = mysql_query("SELECT count(id) FROM login WHERE user='$user' and pass='$pass'");
$result = mysql_result($get, 0);