Forum Moderators: coopster
I am having difficulty in begin able to pdate members info correctly.
Te problem I am having is that a member can login ok and on their first screen it retrieves their user name ok. But when they click on the Update profile for some reason it retrieves another members info.
Any ideas would be very much appreciated.
Here is what I currently have:
<?
include 'vars.php';
include 'header.php';
mysql_connect($dbhost,$dblogin,$dbpass) OR DIE ("Wrong username or password");
mysql_select_db($db) OR DIE("No such database");
$query = "SELECT * FROM `members`";
$result = mysql_query($query);
$number = mysql_num_rows($result);
for ($i=0;$i<$number;$i++) {
$n[1] = mysql_result($result,$i,'id');
$n[2] = mysql_result($result,$i,'first_name');
$n[3] = mysql_result($result,$i,'last_name');
$n[4] = mysql_result($result,$i,'email');
$n[5] = mysql_result($result,$i,'pass');
$n[6] = mysql_result($result,$i,'mobile_num');
$n[7] = mysql_result($result,$i,'phone');
$n[8] = mysql_result($result,$i,'street');
$n[9] = mysql_result($result,$i,'state');
$n[91] = mysql_result($result,$i,'int_state');
$n[10] = mysql_result($result,$i,'country');
$n[11] = mysql_result($result,$i,'postcode');
$n[12] = mysql_result($result,$i,'user');
$n[13] = mysql_result($result,$i,'resident_type');
$n[22] = mysql_result($result,$i,'status');
$n[14] = mysql_result($result,$i,'charity');
$n[15] = mysql_result($result,$i,'ad_cats');
$n[16] = mysql_result($result,$i,'conf_pass');
$n[17] = mysql_result($result,$i,'gender');
$n[18] = mysql_result($result,$i,'age');
$n[19] = mysql_result($result,$i,'city');
$n[20] = mysql_result($result,$i,'method_of_payment');
$n[21] = mysql_result($result,$i,'paypal_email');
}
echo "<form action=\"update2.php\" method=\"POST\">
<input type=\"hidden\" name=\"id\" value=\"$n[1]\">
<input type=\"hidden\" name=\"charity\" value=\"$n[14]\">
<table align=\"center\" width=\"500\">
<tr><td colspan=\"2\" valign=\"middle\" bgcolor=\"silver\"><p align=\"center\"><font size=\"3\" face=\"times new roman\"><b>Membership Update</b></font></p></td>
</tr>
<tr>
<td>First Name</td>
<td><input type=\"text\" name=\"fname\" size=\"35\" value=\"$n[2]\"></td>
</tr>
<tr>
<snipped a ton of fields - jatar_k>
<tr>
<td>Paypal Details<br><font size=\2\ >(if required)</font></td>
<td><input type=\"text\" name=\"paypal\" size=\"35\" value=\"$n[21]\"></td>
</tr>
<tr>
<td align=center><input type=\"reset\" value=\"CLEAR FORM\"></td>
<td align=center><input type=\"submit\" name=\"submit\" value=\"UPDATE\">
</td>
</tr>
</table>
</form>";
@mysql_close($db);
include 'footer.php';?>
[1][[b]edited by[/b]: jatar_k at 10:23 pm (utc) on April 2, 2004][/1]
please read the forum recommendations regarding shoveling piles of code into a message... it's easier to answer a well-worded question than to untangle a long buggy script.
your first step in debugging should be simplifying your code, learn ways to streamline your processes, and separate the PHP logic bits from the bits that just output HTML.
I am very new to php and have been reading boks for the past two weks and cannot figure out where it is going wrong.
I unfortunatly did not write the php it was done by someone else who unfortuntly has had a family berievement, thats why I am stuck in this as I do not know php.
What I have include above is the update.php
Really? Usually when updating something you'll need to use an sql statement like "UPDATE members SET info=$variable WHERE id=$id"
See the MySQL manual on UPDATE [mysql.com]
No the problem is ont with the updating of the members info it is the part about when they go to update it.
The way it is set up is that whe they want to update there info, first it retireives the current data from the system.
This is where it is going wrong, it pulls another members info from the system.
If you look down the code you will see that there is a statement that points to a update2.php, in that file is where I have those statemements.
<? include 'vars.php';
include 'header.php';
{
mysql_connect($dbhost,$dblogin,$dbpass) OR DIE ("Wrong username or password");
mysql_select_db($db) OR DIE("No such database");
$query = "UPDATE `members` SET `id`= '$id' ,
`first_name` = '$fname',
`last_name` = '$lname',
`mobile_num` = '$mobile',
`street` = '$street',
that is from the update2.php file.
What current happens is they go to a login in page.
They enter there username and pass.
this then takes them in to the members area, and say welcome XXXXX ( this being the users first name)
This part is working ok.
On that page there is a link that syas update my info.
when they clcik on that link is now where it goes wrong.
The system is pulling another members info for them to update, and not theirs.
If you see what I mean
I feel you're problem then is here.
$query = "SELECT * FROM `members`";
Don't you want to limit this query with the members id? It should be unique right? Therefore, you don't need to loop through all the rows returned. So basically what looks to be happening is that you grab all the members, you use a for loop for assigning variables but you'll always end up getting the last member in your database. See what I mean?
Typically one stores the login info in a session [php.net] for quick and easy reference.
I thought though that the way it was set up as the user was already logged in, it would pull that members info, I guess it doesnt.
Any suggestions as to what the text should read so I can change it and see as to what happens
many thanks
Now on the page we're talking about again start off with
session_start();
then the select statement will be...
$query = "SELECT * FROM `members` WHERE id=" . $_SESSION['id'];
$result = mysql_query($query);
//get your results into an array
$row = mysql_fetch_assoc($result);
$n[2] = $row['first_name'];
$n[3] = $row['last_name'];
etc... etc...
include ('vars.php');
if (isset($work)) {
// FIND USER IN DB
mysql_connect($dbhost,$dblogin,$dbpass) OR DIE ("Wrong username or password");
mysql_select_db($db) OR DIE("No such database");
$query = "SELECT * FROM members WHERE user = '$user'";
$result = mysql_query($query);
echo mysql_error();
$number = mysql_num_rows($result);
if ($number == 1) {
$a1 = mysql_result($result,0,'first_name');
$a2 = mysql_result($result,0,'last_name');
$a3 = mysql_result($result,0,'email');
$a4 = mysql_result($result,0,'user');
$a5 = mysql_result($result,0,'pass');
if ($pass == $a5) {
echo "<center>Hello, $a1<br><br>Please</center><center><a href=\"members.php?user=$a4\">CLICK HERE</a></center><center>To enter your members area.</center>";
$s[user] = $user;
I have a feeling I am going to have to do a lot more reading and learn php all together.
I can see this is not going to be easy.
Unfortunatly for me the guy that did write the script was a learner too from what you are telling me.
where woould yo suggest I put that statement about sessions?