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
https://forums.phpfreaks.com/topic/193894-echoing-variables/
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
https://forums.phpfreaks.com/topic/193894-echoing-variables/#findComment-1020422
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
https://forums.phpfreaks.com/topic/193894-echoing-variables/#findComment-1020438
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.