Member Avatar for ZethSchlenker

Alright, maybe I'm having a brain cramp this late at night, but my code is not working, and I have no idea why. Any help? This is simply being used for me right now, so yes, I'm pulling straight from the $_POST.

<?php
session_start();
if($_SESSION['id'] != 5)
{
	echo "NOT ALLOWED";
}
else
{
include('connect.php');
$title = $_POST['title'];
$content = $_POST['content'];

$sql = "INSERT INTO updates (id, title, date_posted, content)
VALUES (LAST_INSERT_ID(), ".$title.", CURDATE(), ".$content."";
}


mysql_query($sql);

?>

assuming that id is an AUTO_NUMBER and title & content are of text data type, try:

$sql = "INSERT INTO updates (id, title, date_posted, content)
VALUES ( NULL, '".$title."', Now(), '".$content."'";
Member Avatar for ZethSchlenker

Hm, I just tried your suggestion, and it's still not working.
The only other page before that is:

<form action='add_check.php' method='post'>
	Title: <input type='text' name='title'  /><br>
	Content: <textarea name='content' cols='100' rows='25'></textarea> 
	<input type='submit' name='add' />
	</form>

But that's just the simple form.

The VALUES clause is missing the closing parenthesis:

$sql = "INSERT INTO updates (id, title, date_posted, content)
VALUES ( NULL, '".$title."', Now(), '".$content."')";
Member Avatar for ZethSchlenker

Thank you very much. It works, now. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.