Mysql insert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Mysql insert

Post 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
                         
                        }

                

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your else has a boolean expression, not an assignment like you probably were intending..
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

explain?
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

else { $last_id == "0"; }

should be

else { $last_id = "0"; }
Post Reply