Its something so simple yet i cant seem to work it out.
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /var/www/projects/admin/login.php on line 27
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /var/www/projects/admin/login.php on line 28
[PHP]1 <?
2
3 session_start();
4
5 //Logged in before?
6 if (!isset($_SESSION)){
7
8 //Did user submit the form?
9 if (isset($_POST))
10
11 {
12
13 $username = $_POST;
14 $pswd = $_POST;
15
16 //connect to MYSQL the select database.
17 mysql_connect("localhost","username","password");
18 mysql_select_db("sitename_com_-_dbname");
19
20 //Look for user in table.
21 $query = "SELECT name FROM users WHERE username='$username' AND pw='$pw'";
22 $result = mysql_query($query);
23
24 //If user found assign session variables
25 if(!$result)
26 {
27 $_SESSION = mysql_result($result,0,"name");
28 $_SESSION = mysql_result($result,0,"username");
29 echo "Logged in.";
30 }
31
32 //If user hasnt logged in before show login form.
33 }else{
34 include 'login.html';
35 }
36
37 //The user has returned.
38 }else{
39 $name = $_SESSION;
40 echo "Welcome back! - <a href='logout.php'>Logout $username</a>";
41 }
42 ?>[/PHP]
So if you fancy a crack please do... i bet its so simple yet its annoying me.
Comments
i looked it up and im not sure but try not putting "name" and "username" in front of the result() tag.
newb trying to help!!
[PHP]
<?
$query = mysql_query("select name from users where name='$name and pw='$pw'");
$count = mysql_num_rows($query);
if($count == 1)
{
$row = mysql_fetch_assoc($query);
$username = $row;
$pass = $row;
$_SESSION = $username;
$username = $_SESSION;
echo "Logged In ";
}
else
{
echo "Log in incorrect";
}
?>
[/PHP]
you missed an apostrophe after $name
If you look at it $pswd is being defined for the password but in your query you have $pw. Try this
[PHP]<?
2
3 session_start();
4
5 //Logged in before?
6 if (!isset($_SESSION)){
7
8 //Did user submit the form?
9 if (isset($_POST))
10
11 {
12
13 $username = $_POST;
14 $pswd = $_POST;
15
16 //connect to MYSQL the select database.
17 mysql_connect("localhost","username","password");
18 mysql_select_db("sitename_com_-_dbname");
19
20 //Look for user in table.
21 $query = "SELECT name FROM users WHERE username='$username' AND pw='$pswd'";
22 $result = mysql_query($query);
23
24 //If user found assign session variables
25 if(!$result)
26 {
27 $_SESSION = mysql_result($result,0,"name");
28 $_SESSION = mysql_result($result,0,"username");
29 echo "Logged in.";
30 }
31
32 //If user hasnt logged in before show login form.
33 }else{
34 include 'login.html';
35 }
36
37 //The user has returned.
38 }else{
39 $name = $_SESSION;
40 echo "Welcome back! - <a href='logout.php'>Logout $username</a>";
41 }
42 ?>[/PHP]
Photoshop Tutorials- Coming soon
Premium PHP Scripts- Coming soon
Haha i should really do some work so i can remove all the coming soon's