Box Posted March 2, 2010 Share Posted March 2, 2010 heres the snipit of code and it is in<? ?> brackets if ($_POST["cid"]) { $memlist="SELECT * FROM members WHERE id='$_GET[cid]'"; $result=mysql_query($memlist); $row=mysql_fetch_array($result); if ($curlevel < 4) { die("You do not have access to do this"); } elseif ($curlevel <= $row['userlevel']) { die("You cannot change a password of the same level or higher"); } else { mysql_query("UPDATE members SET password='".md5($_POST['cpw'])."' WHERE id='".$_POST['cid']."'")or die( mysql_error()); echo("Password for user ".$row['username']." changed"); } // end of update user level check } the code works and the password is changed but the line echo("Password for user ".$row['username']." changed"); omits the username there is a username field in the database that isnt blank any ideas im completely stumped as this would normally work fine. Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 2, 2010 Share Posted March 2, 2010 heres the snipit of code and it is in<? ?> brackets if ($_POST["cid"]) { $memlist="SELECT * FROM members WHERE id='$_GET[cid]'"; $result=mysql_query($memlist); $row=mysql_fetch_array($result); if ($curlevel < 4) { die("You do not have access to do this"); } elseif ($curlevel <= $row['userlevel']) { die("You cannot change a password of the same level or higher"); } else { mysql_query("UPDATE members SET password='".md5($_POST['cpw'])."' WHERE id='".$_POST['cid']."'")or die( mysql_error()); echo("Password for user ".$row['username']." changed"); } // end of update user level check } the code works and the password is changed but the line echo("Password for user ".$row['username']." changed"); omits the username there is a username field in the database that isnt blank any ideas im completely stumped as this would normally work fine. It could be a number of things. Perhaps "username" is not the column name in your database. Maybe its "Username" or "UserName" This is case sensitive. Also it could be that you are formulating your SQL statement in a way that isn't producing the expected results. The saying Garbage in = Garbage out would apply in that case. If the column name is correct try echoing the SQL statement after it is pieced together and then running that statement in your phpmyadmin to ensure that you are getting the right result. Quote Link to comment Share on other sites More sharing options...
F00Baron Posted March 2, 2010 Share Posted March 2, 2010 That looks like it should work. You could try mysql_fetch_assoc() instead of mysql_fetch_array(). The documentation says mysql_fetch_array() should do both integer subscripts and column names by default but who knows. Quote Link to comment Share on other sites More sharing options...
Box Posted March 2, 2010 Author Share Posted March 2, 2010 I've just realised the error! my second line of php was wrong $memlist="SELECT * FROM members WHERE id='$_GET[cid]'"; should have be $memlist="SELECT * FROM members WHERE id='$_POST[cid]'"; thanks for the suggestions though Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 2, 2010 Share Posted March 2, 2010 I've just realised the error! my second line of php was wrong $memlist="SELECT * FROM members WHERE id='$_GET[cid]'"; should have be $memlist="SELECT * FROM members WHERE id='$_POST[cid]'"; thanks for the suggestions though You would have known that if you followed my instructions Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.