Nomadic Posted October 12, 2009 Share Posted October 12, 2009 I've searched all over the web (including these forums) for the answer to this. I've found plenty of posts and articles on it, the problem is that none of them actually work when I try them. So what am I trying to do? I'm just trying to post some news into a mySQL database where some currently working scripts can pull it out and serve it up as news posts and rss feed input. No matter what I do though I can't get it to post the information into the database. Here's the PHP code I am using: <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $dbname = 'rss'; mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to mysql"); mysql_select_db($dbname) $header=$_POST['header']; $description=substr($_POST['content'],0,20)."..."; $content=$_POST['content']; mysql_query("INSERT INTO feeds (id, title, description, content) VALUES ('NULL','$header','$description','$content')") or die("Unable to insert into table"); ?> And here's the HTML for the posting form in case you need it: <form name="form1" method="post" action="postingnews.php"> <td><table width="100%" cellpadding="3" cellspacing="1"> <tr><td colspan="3"><strong>Update News:</strong></td></tr> <tr><td width="78">Header:</td> <td width="294"><input name="header" type="text" id="header"></td></tr> <tr><td valign="top">Content:</td> <td><textarea name="content" cols=50 rows=6 id="content"></textarea></td></tr> <td>Format:</td> <td> <button type="button" onclick="insert('content', '<b>', '</b>');" title="Bold"><b>Bold</b></button> <button type="button" onclick="insert('content', '<u>', '</u>');" title="Uline"><u>Uline</u></button> <button type="button" onclick="insert('content', '<i>', '</i>');" title="Italic"><i>Italic</i></button> <button type="button" onclick="insert('content', '<a href="page link">', '</a>');" title="Link">Link</button> <button type="button" onclick="insert('content', '<img src="', '">');" title="Image">Image</button> <button type="button" onclick="insert('content', '', '<br>');" title="Line Break">Line Break</button> </tr></td> <tr><td> </td> <td> </td> <td><input type="submit" name="Submit" value="Post"></td></tr> </table></td> </form> Any insight into what I am fudging up would be appreciated greatly. Quote Link to comment https://forums.phpfreaks.com/topic/177370-solved-posting-data-to-a-mysql-table/ Share on other sites More sharing options...
taquitosensei Posted October 12, 2009 Share Posted October 12, 2009 try this $sql="INSERT INTO feeds (id, title, description, content) VALUES ('NULL','$header','$description','$content')"; echo $sql; mysql_query($sql); see if it makes sense. You can post it here and someone will try to help. Quote Link to comment https://forums.phpfreaks.com/topic/177370-solved-posting-data-to-a-mysql-table/#findComment-935198 Share on other sites More sharing options...
Nomadic Posted October 12, 2009 Author Share Posted October 12, 2009 unfortunately it gives me this: Parse error: parse error in C:\Program Files\wamp\www\RCoC Test Area\postingnews.php on line 19 line 19 being: $sql="INSERT INTO feeds (id, title, description, content) Quote Link to comment https://forums.phpfreaks.com/topic/177370-solved-posting-data-to-a-mysql-table/#findComment-935204 Share on other sites More sharing options...
farkewie Posted October 12, 2009 Share Posted October 12, 2009 Hi, Try this. <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $dbname = 'rss'; mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to mysql"); mysql_select_db($dbname); $header = addslashes($_POST['header']); $description= addslashes(substr($_POST['content'],0,20)."..."); $content = addslashes($_POST['content']); $query = "INSERT INTO feeds (id, title, description, content)VALUES ('','$header','$description','$content')"; $result = mysql_query($query) or die(mysql_error()); ?> addslashes is not the best option but it is a start. also you should not need to insert NULL into an id column as this should not be allowed to be null Quote Link to comment https://forums.phpfreaks.com/topic/177370-solved-posting-data-to-a-mysql-table/#findComment-935212 Share on other sites More sharing options...
Nomadic Posted October 12, 2009 Author Share Posted October 12, 2009 Hi, Try this. <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $dbname = 'rss'; mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to mysql"); mysql_select_db($dbname); $header = addslashes($_POST['header']); $description= addslashes(substr($_POST['content'],0,20)."..."); $content = addslashes($_POST['content']); $query = "INSERT INTO feeds (id, title, description, content)VALUES ('','$header','$description','$content')"; $result = mysql_query($query) or die(mysql_error()); ?> addslashes is not the best option but it is a start. also you should not need to insert NULL into an id column as this should not be allowed to be null Works like a charm. Thanks a ton Oh and as an aside since you mentioned it. My ID column is set to auto-increment which means that NULL value causes it to tick over to the next number. I could probably just leave it out but I stuck it in there to remember that I have an ID column (which may factor in later should I add page links). Quote Link to comment https://forums.phpfreaks.com/topic/177370-solved-posting-data-to-a-mysql-table/#findComment-935221 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.