Jump to content

Keeps coming out as true!


Dat

Recommended Posts

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.  :wtf: 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

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'];
}
?>

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
?> 

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.