Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 49
  1. #16
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Would it be UserID or just id as it is in my database? The reason I ask is at the moment it enters the sender as id = 0 not the person that is logged in.

    Actually it shows who ever logs in as being id=0. I just logged in as another user and it shows the test message I sent when logged in as me.
    Last edited by Foster; 03-15-2013 at 10:08 AM.

  2. #17
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    yes whatever the column name is in the database
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  3. #18
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I changed it and it still shows any user logged in as having an id = 0.

    Any ideas?

  4. #19
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    did you add session_start(); to the top of the page?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  5. #20
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Yeah I did.

  6. #21
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    have you checked the database
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  7. #22
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    post your new login script again please
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  8. #23
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    PHP Code:
    <?php
    session_start
    ();
    include(
    "config.php"); 

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    // username and password sent from form
    $username=$_POST['username'];
    $password=$_POST['password'];

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername stripslashes($username);
    $mypassword stripslashes($password);
    $myusername mysql_real_escape_string($username);
    $mypassword mysql_real_escape_string($password);

    $sql="SELECT * FROM users WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);
    $row mysql_fetch_array($results);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);

    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){

    // Register $myusername, $mypassword and redirect to file "login_success.php"
    $_SESSION['id'] = $row['id'];
    session_register("username");
    session_register("password");
    header("location:myregiments.html");
    }
    else {
    echo 
    "Wrong Username or Password";
    }

  9. #24
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    comment out the redirect and echo the row

    PHP Code:
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    $_SESSION['id'] = $row['id'];
    session_register("username");
    session_register("password");
    //header("location:myregiments.html");

    echo "SESSION['id'] = ".$_SESSION['id']."<br>";
    echo 
    "row['id'] = ".$row['id']."<br>"
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  10. #25
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I get this error
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a7397689/public_html/checklogin.php on line 25
    And this from the echo
    SESSION['id'] =
    row['id'] =

  11. #26
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Right the error was caused by an s on the end of $result and that is now showing the user id is logged in. That means pm's to that person is now visible but it's still showing the sender as having no id. Best look through the code.

  12. #27
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I've sorted the sending and viewing issues thanks to those who helped. I'm now looking to add the option of selecting a recipient from a list as people may not always know the full name or correct spelling of a user.

  13. #28
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you want it as a dropdown box or textbox with autofill lookup?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  14. #29
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    the first is easy,

    the latter i use that script a lot and it works fine,

    you need this in the head:

    PHP Code:
    <head>
    <
    script>
    function 
    showUser(str)
    {
    if (
    str=="")
      {
      
    document.getElementById("text1").value="";
      return;
      }
    if (
    window.XMLHttpRequest)
      {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      
    xmlhttp=new XMLHttpRequest();
      }
    else
      {
    // code for IE6, IE5
      
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (
    xmlhttp.readyState==&& xmlhttp.status==200)
        {
    //alter this line to the field you want and change from innerHTML to value eg..
        
    document.getElementById("text1").value=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
    }
    </script>


    </head> 
    in this example you need a file called getuser.php with the following in it.

    PHP Code:
    <?php

    $q
    =$_GET["q"];

    include(
    "connect.php");
    $resultmysql_query("SELECT * FROM users WHERE id = '".$q."'" );
    $row mysql_fetch_assoc($result)
    echo 
    $row[name];
    ?>
    and for your form you need an onchange event to call it

    (doesnt need to be a seperate field)

    PHP Code:


    <form action="update.php"  method="post">

    <
    select name="sel1" id="sel1" onchange="showUser(this.value);">
                <
    option value="1">select 1</option>
                    <
    option value="2">select 2</option>
                <
    option value="3">select 3</option>
                <
    option value="4">select 4</option>
                <
    option value="5">select 5</option>
    </
    select>

    <
    input type="text" id="text1" name="text1" value="">
    <
    input type="submit">
    </
    form
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  15. #30
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I would like to do it with a look up option.


 
Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •