Dat
09-14-2009, 09:24 PM
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'];
}
?>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'];
}
?>
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'];
}
?>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'];
}
?>