Jump to content

echoing variables


Box

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.