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

I don't see your Query that selects the info from the database. Such as:

$sql = SELECT `info` FROM `table`

$result = mysql_query($sql) or die(mysql_error());

 

If your pulling the info from the db, gonna need that.

THen instead of $rs at the end of array use $result

What your If statement will do is see if the $var that you are checking does not equal exactly what you have between the quotes.  You may find a more accurate fuction on this page http://fr3.php.net/manual/en/ref.strings.php pluss loads more things you can do with strings, enjoy.

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.