papillonstudios Posted June 3, 2009 Share Posted June 3, 2009 ok i'm tryng to make a blog system, and i'm starting with Post a Blog Entry. I have made the form with the code <?php //Checks to see if theyre allowed to edit their profile if ($uCan['admin']) { //Double security incase the admin hasn't set a guest membergroup if ($uId) { //If the form hasn't been submitted, show it. if (!$_POST['post']) { ?> <p><h3>Blog -> Add New Post</h3></p> <br> <form method="post"> <input type="hidden" name="username" value="$username"> <table width="50%"> <tr><td>Title <input type="text" class="textfield" name="title"></td></tr> <tr><td>Date <input type="text" class="textfield" name="date" /> </td></tr> <tr><td></td></tr> <tr><td>Body <textarea cols="40" rows="10" class="textbox" name="body"></textarea></td></tr> <tr><td><input type="submit" name="submit" value="Post Topic"></td></tr> </table> </form> <?php } //Or else it has been submitted... else { //Get information from the forms secure it all. $title = secure($_POST['title']); $username = secure($_POST['username']); $date = secure($_POST['date']); $body = secure($_POST['body']); $post = mysql_query("INSERT INTO `blog` VALUE ('$title', '$username', '$date', '$body')"); if ($post) echo 'The topic has been posted, <a href="index.php?action=general">Click Here</a> to go back to Blog Settings.'; else{ echo "Error message = ".mysql_error(); //A query to update everything } } } } ?> but when you submit the form it doesnt insert the data into the blog table. It just refreshes the page from what it look like. BTW, the username hidden field and variable in the username of the user posting the blog entry. Link to comment https://forums.phpfreaks.com/topic/160725-sql-insert/ Share on other sites More sharing options...
Alex Posted June 3, 2009 Share Posted June 3, 2009 Use: if(isset($_POST['something']) && isset($_POST['somethingelse'])).. Instead of: if($_POST['post']).. Also, why would you have the date as a text field? They could put whatever they want. You should use date as a unix time stamp. You can use time(), and when fetching the blog posts use date() Link to comment https://forums.phpfreaks.com/topic/160725-sql-insert/#findComment-848219 Share on other sites More sharing options...
cltn77 Posted June 3, 2009 Share Posted June 3, 2009 try to use $_POST['submit']. Link to comment https://forums.phpfreaks.com/topic/160725-sql-insert/#findComment-848222 Share on other sites More sharing options...
papillonstudios Posted June 3, 2009 Author Share Posted June 3, 2009 thanks guys that worked Link to comment https://forums.phpfreaks.com/topic/160725-sql-insert/#findComment-848235 Share on other sites More sharing options...
Ken2k7 Posted June 3, 2009 Share Posted June 3, 2009 $post = mysql_query("INSERT INTO `blog` (title, username, date, body) VALUE ('$title', '$username', '$date', '$body')"); List the fields in blog you want to INSERT the data into. If you don't list them, MySQL will assume you'll INSERT to every column. I don't know your column names, so I guessed. Just an example. Link to comment https://forums.phpfreaks.com/topic/160725-sql-insert/#findComment-848237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.