Jump to content

[SOLVED] Checking if variable has a specific text value help??


New Coder

Recommended Posts

Hello all,

I was wondering if anybody could help me.

I'm trying to see if a variable that is created from a DB value can be checked for a specific value, and then carry out an if statement depending on the result.

 

Heres what I have tried.

<?php

$num = mssql_num_rows ($rs);
if ($num !=0)
{			
$row = mssql_fetch_array( $rs );
$list = "<table border=\"0\" cellpadding=\"4\" width=\"98%\">";
	$list .= "<tr>";
	$list .= "<th>Name</th>";
	$list .= "<td>".$row["name"]."</td>";
	$list .= "<th></th>";
	$staffcode = $row["staffcode"];
$list .= "</table>";

echo( $list . "<br>" );
}
else
{ header("Location:no_details.php");
exit();}
mssql_close ( $conn );	

if ( $staffcode != "Standard User" )
{	
echo ( "
<form action=\"edit_details.php\" method=\"post\">
<table border=\"0\" cellpadding=\"4\" width=\"98%\">
<tr>
<th width=\"75%\">Staff Code</th>
<td><input type=\"text\" value=\"$staffcode\" name=\"staffcode\"></td>
</tr>
</table>
<input type=\"submit\" value=\"Save\"></form> " );
}
else
{
echo ( "
<table border=\"0\" cellpadding=\"4\" width=\"98%\">
<tr>
<th width=\"75%\">Staff Code</th>
<td>$staffcode</td>
</tr>
</table> " );
}

?>

 

But it's just ignoring the if statement and carrying out the first part of the If regardless.

 

Can I do it this way?

What am I doing wrong?

 

Thanks in advance

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.