Forum Moderators: coopster
OK here is my database
--------------------database I’m working with----------
CREATE TABLE users (
userid int(25) NOT NULL auto_increment,
first_name varchar(25) NOT NULL default '',
last_name varchar(25) NOT NULL default '',
email_address varchar(25) NOT NULL default '',
username varchar(25) NOT NULL default '',
password varchar(255) NOT NULL default '',
memberreferredby varchar(255) NOT NULL default '',
yourreferrallink varchar(255) NOT NULL default '',
info text NOT NULL,
user_level enum('0','1','2','3','4','5') NOT NULL default '0',
signup_date datetime NOT NULL default '0000-00-00 00:00:00',
last_login datetime NOT NULL default '0000-00-00 00:00:00',
activated enum('0','1') NOT NULL default '0',
PRIMARY KEY (userid)
) TYPE=MyISAM COMMENT='Membership Information';
--------------------database I’m working with------------------------
This next code is my login success code for right after the user logs in its called login_success.php
------------------------------------------------------------------------------
<?
session_start();
echo "Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."! You have made it to the check in area!<br /><br />";
echo "Your user level is ". $_SESSION['user_level']." Which means the following: <br />";
if($_SESSION['user_level'] == 0){
echo "- you have 5 referrals to go to finish <br />";
echo "<img src='pics/stars/0o5.gif' <br /><br />";
}
if($_SESSION['user_level'] == 1){
echo "- you have 4 referrals to go to finish <br />";
echo "<img src='pics/stars/1o5.gif' <br /><br />";
}
if($_SESSION['user_level'] == 2){
echo "- you have 3 referrals to go to finish <br />";
echo "<img src='pics/stars/2o5.gif' <br /><br />";
}
if($_SESSION['user_level'] == 3){
echo "- you have 2 referrals to go to finish <br />";
echo "<img src='pics/stars/3o5.gif' <br /><br />";
}
if($_SESSION['user_level'] == 4){
echo "- you have 1 referral to go to finish <br />";
echo "<img src='pics/stars/4o5.gif' <br /><br />";
}
if($_SESSION['user_level'] == 5){
echo "- you have 0 referrals to go please check another conga to join. <br />";
echo "<img src='pics/stars/5o5.gif' <br /><br />";
}
?>
<html><head>
<title>Change Profile Info</title>
</head><body>
<h1>Change Profile Info</h1>
<p>Fill out only the fields you'd like to change:</p>
<form action="changestars.php" method="post">
Referrals Done: <input type="text" name="user_level" size="20"><br />
<input type="submit" value="Update Profile" name="submit"><input type="reset" value="Reset Entries" name="reset"></form>
</body></html>
<?
echo "<br /><a href=logout.php>Logout</a><br>";
?>
-----------------------------end of login_success.php-------------------------
The place I’m lost is updating or inserting a different number into the database the $user_level variable needs to be changed once they clck the button listed above, the part above where it lists the reference to changestars.php which this page is called.
I have tried about everything and some page I see are renaming there variables to like $new_user_level then assigning it to the user_level spot in the database for that one specific user, I had it working once and lost the code messing with it, but the code changed everyones user level at once to the same thing that wasn’t what I wanted to do, so is something like this right for code or did I miss something?
mysql_query(" UPDATE users SET user_level='$user_level' WHERE id='$userid'");
If anybody wants to help me message me or email me, I don’t know the forum policies here or I would list a live version for you to mess with because its all online right now.
This is just a stab in the dark, because I can't see what's happening in the script changestars.php. But... wouldn't this line
Referrals Done: <input type="text" name="user_level" size="20"><br /> really be
Referrals Done: <input type="text" name="username" size="20"><br />
I'm simply guessing...
In changestars.php you would be retrieving the POST'ed values to execute this code:
mysql_query(" UPDATE users SET user_level='$user_level' WHERE id='$userid'");
In changestars.php you may have a line like
$userid = $_POST['username'];
This retrieves the value that you submitted from the form.
Does any of that look familiar? Could you give us the piece of changestars.php where you retrieve the POST values.
I would list a live version for you to mess with because its all online right now
The way my code reads is there is really different sections
especially the user_level
so really in real life when i talk about referrals it = user_level
this number you can see goes from 0-5 and stops, but the only thing im trying to do is say let the user login and change that one thing, so you login you get empty box where it says something like "REFERRALS" next to it and they fill in any number from 1-5 to have it insert into there own personal record called user_level for them specific
$query = "UPDATE users SET user_level='" . $_POST['user_level'] . "' WHERE id='" . $_POST['userid'] . "'";
Now, if it's not working as expected, I have it echo the query and stop so I can verify that I'm sending the right query:
$result = mysql_query($query);
echo "<br><br>$query"; exit();
Now try that query in your mysql client. Does it do what you expect? What do you need to change to get it to work in the client? Missing variable value? Now you know where to trace back to.