Jump to content

SQL INSERT


Recommended Posts

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
Share on other sites

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.