Jump to content

[SOLVED] Insert Problem


Nexy

Recommended Posts

Why Hello There!  :) I seem to be having a problem with insertion. I don't see what's the problem.

 

<?php
$news = mysql_real_escape_string($_POST['text']);
$news = nl2br($_POST['text']);
$title = mysql_real_escape_string($_POST['title']);
$set = "1";
$date = date('m-j-Y');

if($_POST['subnews'] && !empty($news) && !empty($title)) {

if($_SESSION['username']) {
mysql_query("INSERT INTO news(user, subject, date, news) VALUES ('".$_SESSION['username']."', '$title', '$date', '$news')");
$set = "2";
}
else if($_COOKIE['user']) {
mysql_query("INSERT INTO news(user, subject, date, news) VALUES ('".$_COOKIE['user']."', '$title', '$date', '$news')");
$set = "2";
}
}

if($_SESSION['username'] || $_COOKIE['user']) {
echo 	"<form action='#' method='post'>
<fieldset id='account'>
<legend>You can add news in here:</legend>

<p style='color: white'>HTML format codes are allowed.</p>

<label for='title'>Title:</label>
<input type='text' id='title' name='title' tabindex='6' style='width: 200px' />
<p />
<label for='text'>News:</label><br />
<textarea id='text' name='text' rows='10' cols='40' tabindex='7'></textarea>
<br />
<input type='submit' id='subnews' name='subnews' value='Add News' />
<input type='reset' value='Clear News' />

</fieldset>
</form>";
} else {
include("includes/error.php");
}

?>

 

Ok, the problem is, it only Inserts once. When I click submit again with something in there, it doesn't insert anything. Also, for some reason, the field called 'id'(primary key) starts off at 0, when with some other of my tables, id starts off at 1. Any idea what may be wrong?

 

Thank You!

Link to comment
https://forums.phpfreaks.com/topic/108263-solved-insert-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.