...

View Full Version : User login system; retrieving user specific data.



nobackseat88
12-21-2007, 09:27 PM
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.

mic2100
12-21-2007, 10:04 PM
Hi,

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

SeeIT Solutions
12-21-2007, 10:08 PM
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

msg_id user_id msg timestamp



//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']);
}

nobackseat88
12-22-2007, 09:12 PM
Yes, I have start off code, but it didn't always work and wasn't very reliable. Let me post it in next post.

nobackseat88
12-22-2007, 09:33 PM
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


<?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


<?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


<?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.

SeeIT Solutions
12-23-2007, 12:15 AM
Could it be that you are selecting profile from code, but the table is called users?

nobackseat88
12-25-2007, 01:46 AM
Profile from code? What do you mean by that?

jlhaslip
12-25-2007, 02:03 AM
check the profile_edit page.


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'];

SeeIT Solutions
12-25-2007, 06:18 AM
}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.

nobackseat88
12-26-2007, 05:47 PM
Ah, good eye. Thanks, will try it now.

nobackseat88
12-26-2007, 06:18 PM
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);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum