New Coder Posted February 15, 2007 Share Posted February 15, 2007 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 https://forums.phpfreaks.com/topic/38608-solved-checking-if-variable-has-a-specific-text-value-help/ Share on other sites More sharing options...
Greaser9780 Posted February 15, 2007 Share Posted February 15, 2007 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 Link to comment https://forums.phpfreaks.com/topic/38608-solved-checking-if-variable-has-a-specific-text-value-help/#findComment-185276 Share on other sites More sharing options...
scottybwoy Posted February 15, 2007 Share Posted February 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/38608-solved-checking-if-variable-has-a-specific-text-value-help/#findComment-185286 Share on other sites More sharing options...
New Coder Posted February 15, 2007 Author Share Posted February 15, 2007 Awesome. Thanks Link to comment https://forums.phpfreaks.com/topic/38608-solved-checking-if-variable-has-a-specific-text-value-help/#findComment-185291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.