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.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts

    User login system; retrieving user specific data.

    I have a question. I have a user login system. I want data the user may enter to show up when the user logs back in. Such as a reminder message. to show up when they log in. How would I do this? Just make a new column in the mysql database and store it in there and retrieve by user id, right? Could someone also give me a head start on coding for this.

    Thanks.

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    Hi,

    do you have any code already that you have been trying to get working?

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    That would be a way to do it, another table with login messages would probably be better so you aren't running update queries on the user database all the time.

    Database msgs
    Code:
    msg_id       user_id          msg           timestamp

    PHP Code:
    //User logs in

    $result mysql_query("SELECT * FROM `msgs` WHERE `user_id` = '".$login_id."' LIMIT 1");//login_id = id number of logged in user
    if (mysql_num_rows($result) > 0) { //if result not empty
      
    $msgdata mysql_fetch_assoc($result); // assign result to $msgdata
      
    mysql_query("DELETE FROM `msgs` WHERE `msg_id` = '".$msgdata['msg_id']."'"); //remove the row from database so it doesn't show next time
    }

    //to display - put this where you want it to show
    if (isset($msgdata) && is_array($msgdata)) {
      echo 
    "Reminder: ".$msgdata['msg']."<br />Set on: ".date("dmY G:i:s",$msg['timestamp']);


  • Users who have thanked SeeIT Solutions for this post:

    nobackseat88 (12-25-2007)

  • #4
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Yes, I have start off code, but it didn't always work and wasn't very reliable. Let me post it in next post.

  • #5
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    I did mine more of a profile code based style. I just wanted to get an idea of the way you guys would do it. Im not that good at this stuff, so I didn't get too complicated...config.php was included in all files, profileedit.php got the code and stored it in a database, and viewprofile.php gets the code from the database and shows it. Is there a better way of doing this? Not feeling this is the easiest way...

    config.php

    Code:
    <?php
    $server = "localhost";	// server to connect to.
    $database = "databasename";	// the name of the database.
    $db_user = "user";	// mysql username to access the database with.
    $db_pass = "pass";	// mysql password to access the database with.
    $table = "users";		// the table that this script will set up and use.
    ?>
    profileedit.php

    Code:
    <?php
    <form action=\"profile.php\" method=\"post\">Profile Code:<br><br>";
    echo "<textarea name=\"pcoding\" rows=\"10\" cols=\"70\" onKeyDown=\"limitText(this.form.pcoding,this.form.countdown,500);\" 
    onKeyUp=\"limitText(this.form.pcoding,this.form.countdown,500);\">";
    
    $con = mysql_connect("localhost","databasename","pass");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("databasename", $con);$result = mysql_query("SELECT profile FROM code");while($row = mysql_fetch_array($result))
      {
      echo $row['profile'];
      
      }mysql_close($con);
    
    echo "</textarea><br><font size=\"1\">(Maximum characters: 300)<br>
    You have <input readonly type=\"text\" name=\"countdown\" size=\"3\" value=\"500\"> characters left.</font>
    <br>
    <input type=\"submit\" />
    </form>
    ?>
    viewprofile.php

    Code:
    <?php
    // The code I use to store the user's username in the variable $who
    echo "Welcome to a persons profile.<br><br>";
    ?>
    <?php
    $con = mysql_connect("localhost","databasename","pass");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("databasename", $con);
    $result = mysql_query("SELECT profile FROM users WHERE username=$who");while($row = mysql_fetch_array($result))
      {
      echo $row['profile'];
      echo "<br />";
      }mysql_close($con);
    ?>
    What the database looked sorta like:

    tables: users
    fields: id, username, password, email, realname, profile


    ------

    Here are some problems I had and am still having.

    The error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/username/public_html/login/viewprofile.php

    Also, when viewing the profile, it always showed the code 3 times. Tripled whatever I entered in profileedit.php.

    ANY help would be appreciated.

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Could it be that you are selecting profile from code, but the table is called users?

  • #7
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Profile from code? What do you mean by that?

  • #8
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    check the profile_edit page.
    Code:
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("databasename", $con);$result = mysql_query("SELECT profile FROM code");while($row = mysql_fetch_array($result))
      {
      echo $row['profile'];

  • #9
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
      }mysql_select_db("databasename"$con);$result mysql_query("SELECT profile FROM code");while($row mysql_fetch_array($result)) 
    On that line, you have "SELECT profile FROM code"

    code isn't the name of the table in the database by other information you've given.

  • #10
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Ah, good eye. Thanks, will try it now.

  • #11
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    viewprofile.php can't get the value in profile?
    <?php
    $mysite_username = \\ the code I use to get their username, this works no error here.
    echo "Welcome to your profile.<br><br>";

    $con = mysql_connect("localhost","database","pass");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }mysql_select_db("database", $con);
    $result = mysql_query("SELECT profile FROM users WHERE username=$mysite_username");while($row = mysql_fetch_array($result))
    {
    echo $row['profile'];
    echo "<br />";
    }mysql_close($con);
    ?>


  •  

    Posting Permissions

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