matthew798 Posted September 9, 2008 Share Posted September 9, 2008 Hey guys Sweet and simple, here it is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body bgcolor="black"> <table width="696" border="0"> <tr> <td><form action="newsprocess.php" method="POST"> <input name="title" type="text" width="200px" /></input> <br /> <br /> <input name="body" type="text" width="400px" height="300px" /></input> <input type="submit" /></input> </form></td> <td valign="top"><strong>To insert an image: The image must be hosted on the internet, I.E. located at an HTTP address</strong></td> </tr> </table> </body> </html> <?php $body = $_POST['body']; $title = $_POST['title']; mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("test") or die(mysql_error()); echo "Connected to Database"; mysql_query("INSERT INTO news (`title`, `body`, `date`) VALUES ( $title, $body, now())") or die(mysql_error()); echo "Data Inserted!"; ?> Why am i geting this when i enter hello in both text fields:Unknown column 'Hello' in 'field list' Quote Link to comment https://forums.phpfreaks.com/topic/123472-databse-problem/ Share on other sites More sharing options...
cooldude832 Posted September 9, 2008 Share Posted September 9, 2008 try escaping using mysql_real_escape_string() on the inputting variables Quote Link to comment https://forums.phpfreaks.com/topic/123472-databse-problem/#findComment-637710 Share on other sites More sharing options...
sasa Posted September 9, 2008 Share Posted September 9, 2008 change mysql_query("INSERT INTO news (`title`, `body`, `date`) VALUES ( $title, $body, now())") or die(mysql_error()); to mysql_query("INSERT INTO news (`title`, `body`, `date`) VALUES ( '$title', '$body', now())") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/123472-databse-problem/#findComment-637712 Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 Basically because you dont have single quotes around your variable in your Query. Why am i geting this when i enter hello in both text fields:Unknown column 'Hello' in 'field list' Quote Link to comment https://forums.phpfreaks.com/topic/123472-databse-problem/#findComment-637774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.