jaxdevil Posted March 3, 2008 Share Posted March 3, 2008 What did I do wrong? It keeps showing me the highest numbered row is 20. I have a table with 20 rows, that has a field called 'fldact', which is set either 'yes' or 'no'. I am trying to make an if statement that shows an error and will not show the new item entry form if the fields are all marked as 'yes' for the field 'fldact'. As it is now it ALWAYS says it has 20 rows, it is like it is completely ignoring the WHERE clause limiting the results to only the rows marked 'yes'. Here is my code... <?php $sql = "SELECT * FROM `fld` WHERE `fldact`='yes' ORDER BY `id` DESC LIMIT 1"; $query = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($query)) { $tot = $row['id']; $k=20; $fld_id = $row['id']; $fld_id_text = $row['idtext']; } if ($tot=$k){ print "ERROR!<br>"; // This line will not be executed print "You already have the maximum number of fields<br>"; echo $tot; echo $k; } else{ ?> <input type="hidden" name="fld_id" value="<?=$fld_id?>"> <input type="hidden" name="fld_id_text" value="<?=$fld_id_text?>"> <p><div style="padding-left: 60px;"><label for="first_name">Field Value <?=$tot?></label> <input id="fld_name" name="fld_name" type="text" size="30" /> </div></p> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/94131-solved-if-statement-not-working/ Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 If statements need to have two (or sometimes 3) equal signs for comparison: if ($tot==$k){ Link to comment https://forums.phpfreaks.com/topic/94131-solved-if-statement-not-working/#findComment-482189 Share on other sites More sharing options...
jaxdevil Posted March 3, 2008 Author Share Posted March 3, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/94131-solved-if-statement-not-working/#findComment-482195 Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 Glad I could help Link to comment https://forums.phpfreaks.com/topic/94131-solved-if-statement-not-working/#findComment-482197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.