0

I have got this code:

$title = mysql_real_escape_string($_POST['title']);
$description = mysql_real_escape_string($_POST['description']);
$method = mysql_real_escape_string($_POST['method']);

$method1 = '<ul><li>' . implode('</li><li>', explode("\n", $description)) . '</li></ul>';


mysql_query("INSERT INTO recipe (title, description, method) VALUES('".$title."', '".$description."', '".$method1."')");

But it isnt adding anything to my database. Should this code be working?

UPDATE***

I have added the following code but it is not outputing anything

if($success)
{
echo "<h1>Success</h1>";
}
else
{
echo "<h1>Error</h1>";
}
3
  • 1
    Try the query directly in phpmyadmin or your console to see the error. Commented Nov 24, 2011 at 16:35
  • I tried the query in phpmyadmin and it worked? INSERT INTO recipe (title, description, method) VALUES('".$title."', '".$description."', '".$method1."') Commented Nov 24, 2011 at 16:43
  • That might because you aren't entering the same query; PHP would translate $title to the value of $title. What I usually do (as a lazy solution) would be to write $query="bla bla"; and then use $result=mysql_query($query); -- you can 'echo query;' to see what the actual query you're generating is. Commented Nov 24, 2011 at 18:22

3 Answers 3

1

try to wrap your fields with ''

"INSERT INTO recipe (`title`, `description`, `method`) VALUES('".$title."', '".$description."', '".$method1."')");

look on reserved words

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

Comments

1

' and " are inverted in VALUES().

Comments

0

Not need (title, description, method) if you insert the fields in the correct order.

$query = "INSERT INTO recipe VALUES ('".$title."', '".$description."', '".$method1."')";

mysql_query($query);

If the problem is not resolved, try the query directly in phpmyadmin or your console to see the error.

1 Comment

in case this table is contain only those 3 fields

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.