Dat Posted September 14, 2009 Share Posted September 14, 2009 So what I want to do is check if there is a entry for a specified title already in the database, if there is no entry then output the form for it. otherwise just display the 'title' of the entry. Pretty simple i'd say There are no mysql_errors(); The problem is it keeps coming out as "TRUE" and keeps outputting an empty 'title' or the listed title. Please help. <?php $query = "SELECT title FROM entry WHERE entry_id='$id' AND type='$type'"; $result = mysql_query($query); $data = mysql_fetch_array($result); if(!$result) { ?> <form> The form </form> <?php } else { echo $data['title']; } ?> Link to comment https://forums.phpfreaks.com/topic/174244-keeps-coming-out-as-true/ Share on other sites More sharing options...
Rommeo Posted September 14, 2009 Share Posted September 14, 2009 try ; $query = "SELECT title FROM entry WHERE entry_id='$id' AND type='$type'"; $result = mysql_query($query); $data = mysql_num_rows($result); if(!$data) Link to comment https://forums.phpfreaks.com/topic/174244-keeps-coming-out-as-true/#findComment-918538 Share on other sites More sharing options...
Dat Posted September 14, 2009 Author Share Posted September 14, 2009 Still came out as true. :'( Link to comment https://forums.phpfreaks.com/topic/174244-keeps-coming-out-as-true/#findComment-918540 Share on other sites More sharing options...
Dat Posted September 14, 2009 Author Share Posted September 14, 2009 SOLUTION: <?php $query = "SELECT title FROM entry WHERE entry_id='$id' AND type='$type'"; $result = mysql_query($query); $data = mysql_fetch_array($result); // Add this $num = mysql_num_rows($result); //Edit this if($num = 1) { ?> <form> The form </form> <?php } else { echo $data['title']; } ?> Link to comment https://forums.phpfreaks.com/topic/174244-keeps-coming-out-as-true/#findComment-918546 Share on other sites More sharing options...
Rommeo Posted September 14, 2009 Share Posted September 14, 2009 You changed if(!$result) to if(!$data) ? you can also try this ; <?php $query = "SELECT title FROM entry WHERE entry_id='$id' AND type='$type'"; $result = mysql_query($query); $data = mysql_num_rows($result); if ( $data > 0 ) echo title else form tags ?> Link to comment https://forums.phpfreaks.com/topic/174244-keeps-coming-out-as-true/#findComment-918547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.