0
$body = $_POST['post'];
$submit = $_POST['submit'];
$date = date("Y-m-d");
require('php/connect.php');

if($submit)
{

$query = mysql_query("INSERT INTO news (`id`, `body`, `date`) VALUES (NULL, '".$body."', '".$date."')");
header("Location: index.php");
}

I do not understand why this isn't working, I took the query straight from PHP my admin after writing a line simular myself before hand and it still isn't working, can someone hep?

3
  • What does your schema look like? Commented Apr 22, 2011 at 15:18
  • 1
    comment out your header("Location: index.php"); and append or die(mysql_error()); at the end of your query code that will show you what went wrong Commented Apr 22, 2011 at 15:21
  • Even though I've commented out my header I'm still being redirected to index.php O_O Commented Apr 22, 2011 at 15:46

3 Answers 3

2

you definitely should escape your input values using mysql_real_escape_string

With mysql_error you can print out an error message but you need the connection identifier as a parameter.

Sign up to request clarification or add additional context in comments.

Comments

1

I just suggest to handle mysql error

$query = mysql_query("INSERT INTO news (`id`, `body`, `date`) VALUES (NULL, '".$body."', '".$date."')")
 or trigger_error(mysql_error());

and if id is primary key that can not be null

you should escape user input using mysql_real_escape_string function.

What happen if I put "that's it " value in your $body input, your query will fail.

Comments

0

Comment out your header("Location: index.php"); and append or die(mysql_error()); at the end of your query code that will show you what went wrong. You should also "mysql_real_escape_string" your user input before inserting it into your database.

$body = mysql_real_escape_string($_POST['post']);
$submit = $_POST['submit'];
$date = date("Y-m-d");
require('php/connect.php');

if($submit)
{

$query = mysql_query("INSERT INTO news (`id`, `body`, `date`) VALUES (NULL, '$body', '$date')") or die(mysql_error());
//header("Location: index.php");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.