Can anyone tell me why this code does not work? I can't work it out. It's just a simple piece of code to post data into a SQL table called news:
<?php
session_start();
require_once ('../mysql_connect.php'); // Connect to the database.
if (!$_SESSION[valid_id])
{
$loggedin = "You are posting annonymously <a href=\"login.php\">CLICK HERE</a> to login.";
}
ELSE
{
$loggedin = "You are logged in as $_SESSION[valid_user].";
}
?>
<form action="post.php" method="post" name="inputform" class="style1">
<input type="hidden" name="date" value="<?php echo date("y.m.d, H:i:s",time()); ?>">
<input type="hidden" name="moderated" value="0">
<input type="hidden" name="user_id" value="<?php echo "$_SESSION[valid_id]"; ?>">
Title: <br>
<input type="text" size="35" name="title" maxlength=80>
<br>
<br>
<?php
echo "<SELECT name=cat_id>";
$query = "SELECT * FROM news_cats";
$result = mysql_query($query);
echo "<OPTION value = 100>Select a Category --></OPTION>\n";
while ($item = mysql_fetch_array($result))
{
$cat_id = $item[cat_id];
$cat_name = $item[cat_name];
echo "<OPTION value = $cat_id>$cat_name</OPTION>\n";
}
echo "</SELECT>";
?>
<br><br>
Post your coment about this article: <br><textarea name="comment" rows="3" cols="30"></textarea>
<br>
<br>
Link: <br>
<input type="link" size="35" name="link" maxlength=150>
<br>
<font size = "1"><b><?php echo "$loggedin"; ?></b></font>
<br>
<input type="Submit" name="submit" value="Submit">
</form>
</b>
This is the page which posts the code:
<?php
session_start();
require_once ('../mysql_connect.php'); // Connect to the database.
$sql = "INSERT INTO news (title,link,comment,moderated,user_id,date,cat_id) VALUES ('$title','$link','$comment','$moderated','$user_id','$date','$cat_id')";
$result = mysql_query($sql);
echo "<font face=verdana size=2>Thank you! Your message has been submitted for moderation. News posts are normally posted to the site within an hour.\n";
?>