Come on then people.

james.ukjames.uk Junior MemberShared Hoster
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.
A psychopath with dyslexia

Comments

  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    it might not be connecting to the database right
    ban1.gif
  • james.ukjames.uk Junior Member Shared Hoster
    I've checked that, all the database details are correct.
    A psychopath with dyslexia
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    i dont know anything about mysqlresult tags, but maybe the syntax for result() is wrong...just a suggestion

    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!! :)
    ban1.gif
  • $cripts$cripts Beginner Link Clerk
    a simplier way to have a user log in using mysql is
    [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]
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    [PHP]$query = mysql_query("select name from users where name='$name' and pw='$pw'"); [/PHP]

    you missed an apostrophe after $name
    ban1.gif
  • martian2k4martian2k4 Llama Hunter Moderator
    james.uk wrote:
    [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='$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]

    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]
    Free MySpace Layouts- Coming soon
    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
Sign In or Register to comment.