Well, I am having trouble with this MySQL Insert code, but my other ones are working?
This is the one that is not working:
[php]<?php
//connect to MySQL
include(‘mysql_connect.php’);
//Get input
$name =“test”;
$forum =“test”;
$by =“test”;
//Stop code injection
$name = stripslashes($name);
$forum = stripslashes($forum);
$by = stripslashes($by);
$name = mysql_real_escape_string($name);
$forum = mysql_real_escape_string($forum);
$by = mysql_real_escape_string($by);
//Enter data into database
mysql_query(“INSERT INTO thread (name, by, forum) VALUES (’$name’, ‘$by’, ‘$forum’)”);
echo "the db error is: ".mysql_error();
//redirect
//header( ‘Location: http://www.the-rusty-miner.nn.pe/forumdemo/’ ) ;
?>[/php]
I have set the “//Get input” variables all to “test” to make sure it is not an error somewhere else.
As you can see i also added:
[php]echo "the db error is: ".mysql_error();[/php]
And this returned with:
the db error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by, forum) VALUES (test, test, test)' at line 1
[hr]
Now this is the code that does work:
[php]<?php
//connect to MySQL
include(‘mysql_connect.php’);
//Get input
$name = $_POST[‘name’];
$description = $_POST[‘description’];
$cat = $_POST[‘cat’];
//Stop code injection
$name = stripslashes($name);
$description = stripslashes($description);
$cat = stripslashes($cat);
$name = mysql_real_escape_string($name);
$description = mysql_real_escape_string($description);
$cat = mysql_real_escape_string($cat);
//Enter data into database
mysql_query(“INSERT INTO forums (name, description, category) VALUES (’$name’, ‘$description’, ‘$cat’)”);
//redirect
header( ‘Location: http://www.the-rusty-miner.nn.pe/forumdemo/’ ) ;
?>[/php]
I can’t see the problem between the two?
Does anybody know what the problem is?
Thanks