Page 1 of 1

Mysql insert

Posted: Mon Jul 19, 2004 1:46 pm
by pinehead18
I have a mini forum that i wrote. What happens is whenever you create a new topic the sql script looks for the number increment of the old topic and then ads one on. However, if their is currently no fields at all in the sql table then it just gives a white screen as a result. however, if their is one or more rows it ads to the table and forum correctly. Any ideas?
The code is as follows

Code: Select all

<?php
 if (isset($_POST['submit'])) {

                        $con = mysql_connect("localhost","pinehead","") or die(mysql_error());
                        $db = mysql_select_db("lkcforum",$con) or die(mysql_error());

                    $sql = "SELECT tid FROM threads ORDER by tid DESC";
                    $result = mysql_query($sql,$con) or die(mysql_error());
                   $row = mysql_fetch_array($result) or die(mysql_error());
                  if (!isset($row['tid'])) { $last_id = $row['id']; } else { $last_id == "0"; }
                         $newid = $last_id + 1;


                        $sql = "INSERT INTO threads (topic,uname,body,forum_id,topic_id) VALUES    
('$topic','$name','$body','$fid','1')";         
                       mysql_query($sql,$con) or die(mysql_error());
                       mysql_close();
                        echo $sql;

                        $sql = "SELECT tid FROM threads WHERE
                         
                        }

                

?>

Posted: Mon Jul 19, 2004 1:49 pm
by feyd
your else has a boolean expression, not an assignment like you probably were intending..

Posted: Mon Jul 19, 2004 3:15 pm
by pinehead18
explain?

Posted: Mon Jul 19, 2004 3:17 pm
by liljester
else { $last_id == "0"; }

should be

else { $last_id = "0"; }