Having a bit of an issue inserting into sql.
Posted: Mon Jun 25, 2012 2:09 pm
Okay so this is my last part of the news system for my site and I have everything else cleared up, but I don't see anything wrong with this code to insert the new posts. Yes the post page looks like regurgitated ass and rectangles and I have not added in the security to it yet but was trying to get it to post before i went on and did more. It unfortunately hates me and I can't tell why.
function (Yes totally am using the one he used in the tutorial figured if anything its more secure despite i will be the only one posting so I don't think it could be the function.)
function (Yes totally am using the one he used in the tutorial figured if anything its more secure despite i will be the only one posting so I don't think it could be the function.)
function add_post($name, $title, $body) { $name = mysql_real_escape_string(htmlentities($name)); $title = mysql_real_escape_string(htmlentities($title)); $body = mysql_real_escape_string(nl2br(htmlentities($body))); mysql_query("INSERT INTO `posts`(`post_user`, `post_title`, `post_body`, `post_date`) VALUES ('{$name}','{$title}','{$body}', NOW ())"); }post page(testscript is the one the function is in, and that commented out echo I used to test to ensure the post info was getting copied and from what i saw it was.
<?php include('connection.php'); include('testscript.php'); if (isset($_POST[`user`], $_POST[`title`], $_POST[`body`])){ add_post($_POST[`user`], $_POST[`title`], $_POST[`body`]); //echo $_POST['user'], $_POST['title'], $_POST['body'] header(`location: ...\indextest.php`); die(); } ?> <style type="text/css"> #container { background-color:#F2F1E9; width:900px; border:double 1px #000000; -moz-border-radius-topleft: 27px; -moz-border-radius-topright:25px; -moz-border-radius-bottomleft:28px; -moz-border-radius-bottomright:26px; -webkit-border-top-left-radius:27px; -webkit-border-top-right-radius:25px; -webkit-border-bottom-left-radius:28px; -webkit-border-bottom-right-radius:26px; border-top-left-radius:27px; border-top-right-radius:25px; border-bottom-left-radius:28px; border-bottom-right-radius:26px; } </style> <html> <head> <title>Local News</title> </head> <body> <img src="http://monstersagainstcancer.com/images/Logo.gif" width="600" height="150"> <div id="container"> <form action="" method="post"> <p> <label for="user">Name</label> <input type="text" name="user" id="user" /> </p> <p> <label for="title">Title </label> <input type="text" name="title" id="title" /> </p> <p> <label for="body">Body</label> <textarea name="body" id="body" cols="100" rows="20" ></textarea> </p> <input type="submit" value="Add Post" /> </form> </div> </body> </html>