Jump to content

Syntax not being read?


elis

Recommended Posts

Here is the code snippet I'm having trouble with:
[code]$recip= strtolower(mysql_escape_string(trim(strip_tags($_POST['recip']))));
$stringnew = nl2br(mysql_escape_string(trim(strip_tags($_POST['newmsg']))));
$stringnew = str_replace($banned,$edited,$stringnew);
$stringnew = str_replace("'", "^", $stringnew);
$qCheck = "select * from TB_Users where penname = '$recip' limit 1";
$rsCheck = mysql_query($qCheck)  or die(mysql_error());
$bresult = mysql_query("SELECT * FROM blocked_user WHERE username =  '$recip'");
$cresult =  mysql_fetch_array( $bresult );
$dresult = "SELECT * FROM blocked_user WHERE username =  '$recip'";
$eresult =  mysql_query( $bresult );


if (isset($_POST['newsent']))
{
if ($eresult[blocked]==$userpenname)
{
$output.="<br><center><font color=red>MESSAGE2</center></font>";

}
elseif (mysql_num_rows($rsCheck)==0)
{$output.="<font color=red><center> - MESSAGE1</center>";}



elseif ($recip==$userpenname)
{$output.="<br><center><font color=red>MESSAGE3</center></font>";}

[/code]

The two specific areas that I need help with are: (full text in code)
elseif....$recip==$userpenname
and
elseif...$eresult[blocked]==$userpenname

("$userpenname" is defined in another file - "$output" is similar to "echo")
The problem is that "elseif...mysql_num_rows(rscheck)" is being correctly output, but the two I posted above are not printing.
There is no error being reported.
I assume there may be a mistake in the way I've selected the data, but I'm not sure.

A second pair of eyes would really help.
Thank you
Link to comment
https://forums.phpfreaks.com/topic/21333-syntax-not-being-read/
Share on other sites

It's your variable names!  They are driving me crazy!  And they are causing bugs due to that confusion.

[code]$qCheck = "select * from TB_Users where penname = '$recip' limit 1";
$rsCheck = mysql_query($qCheck)  or die(mysql_error());
$rsBlock = mysql_query("SELECT * FROM blocked_user WHERE username =  '$recip'") or die(mysql_error());
$arrBlock =  mysql_fetch_assoc( $rsBlock );

if ($arrBlock['blocked'] == $userpenname) { ...[/code]

When your variable names are consistent, it's easy to see what's going on.  Cheking for errors on every query is also good practice.
Link to comment
https://forums.phpfreaks.com/topic/21333-syntax-not-being-read/#findComment-95127
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.