Jump to content

Problems with blogging script adding blank space to database.


neverbelieve

Recommended Posts

I have tried everything I can't find the problem, therefore I'm hoping some kind experts can point out the problem. ;)

Essentially, I have written a simple PHP script that takes the data from a form and puts it in a MySQL database. My host got hacked recently and therefore I lost it. Upon re-adding the tables and such and re-uploading the code, it now posts with no errors to the database but the fields are blank (except the date) and I have no idea whether this has come from a mistake in the coding, writing of the databases (do the fields need specific settings to accept text data other than changing the type field to TEXT) or something else out of my control? I add the form code and form processing code below to see if anyone notices anything particularly odd!

[code]<form action="processform.php" method="post">
<textarea cols=50 rows=1 name="titleof"></textarea>
<textarea cols=50 rows=20 name="blogcontents">Blog Here!</textarea>
<input type="submit" value="Post It" align="center">
</form>
[/code]

[code]<?php
include("URL");
$connection = mysql_connect($blah,$blah,$blah)
          or die ("Couldn't connect to the database.");
$db = mysql_select_db($database)
          or die ("Couldn't select the database.");
$today = date("Y-m-d");
$query = "INSERT INTO EdBlog ( DateField, CommentField, TitleField) VALUES
        ('$today','$blogcontents','$titleof')";
$result = mysql_query($query)
    or die ("Couldn't add the blog.");
?>[/code]
Link to comment
Share on other sites

First check you table - make sure there are no other fields that MUST have a value inserted (those fields that should NOT be null buit have no default value.)

It maybe simply be that register globals is off (as it should be) if so you must reference teh posted data 'properly'.....As your post uses the post method...
[code]<?php
$query = "INSERT INTO EdBlog ( DateField, CommentField, TitleField) VALUES
        ('$today','" . $_POST['blogcontents'] . "','" . $_POST['titleof'] . "')";
?>
[/code]
I use concatenation in strings just because I find it easier to locate those vars that are relevant....


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.