Mysql insert
Posted: Mon Jul 19, 2004 1:46 pm
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
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
}
?>