Jump to content

Insertion into MySQL 'Text' Field


rish1103

Recommended Posts

I'm trying to write a simple blog script. Basically a varchar(255) title and a text field for the blog entry and it works for short one line entries. everytime the entry is more than two lines, nothing is entered into database and i also donot receive any error messages or anything. Can anyone suggest anything.
Link to comment
Share on other sites

[!--quoteo(post=354570:date=Mar 13 2006, 12:18 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 13 2006, 12:18 PM) [snapback]354570[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Please post your code.
[/quote]

That's the form I use for making the entry into the blog.

[code]
                    <form action="blogin.php" method="post">
                    <font face="Arial" size="2">
                    <input type="text" name="title" size = "60" value ="Title"><br>
                    <input type="text" name="date" value="YYYY-MM-DD"><br>
                    <textarea rows="20" name="entry" cols="60">Make Entry Here</textarea>
                    <br>
                    <input type="Submit"></font>
                    </form>
[/code]

Thats the script that enters the form data into the database. Like i said simple form and simple action. I am unable to understand whats wrong.

[code]
<?
$username="######";
$password="######";
$database="######";

$title=$_POST['title'];
$date=$_POST['date'];
$entry=$_POST['entry'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO blog VALUES ('','$title','$date','$entry')";
mysql_query($query);

print "<font face=\"Arial\">Thankyou for submitting your information! <a href=\"../index.php\">Click here to return home</a></font>";

mysql_close();

?>
[/code]
Link to comment
Share on other sites

I would add some error checking and a minimal amount of data screening:
[code]<?php
$title=mysql_real_escape_string($_POST['title']);
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if ($_POST['date'] != '')  {
   $tmp = strtotime($_POST['date']);
   if ($tmp == -1) date = '0000-00-00';
   else $date = date('Y-m-d',$tmp);
   }
else $date = '0000-00-00';
$entry=mysql_real_escape_string($_POST['entry']);
$query = "INSERT INTO blog VALUES ('','$title','$date','$entry')";
mysql_query($query) or die('Problem with insert query: ' . $query . '<br />' . mysql_error());
?>[/code]

The date checking code will allow your users to input any valid date. (not tested)

Ken
Link to comment
Share on other sites

[!--quoteo(post=354578:date=Mar 13 2006, 12:41 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 13 2006, 12:41 PM) [snapback]354578[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I would add some error checking and a minimal amount of data screening:
[code]<?php
$title=mysql_real_escape_string($_POST['title']);
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if ($_POST['date'] != '')  {
   $tmp = strtotime($_POST['date']);
   if ($tmp == -1) date = '0000-00-00';
   else $date = date('Y-m-d',$tmp);
   }
else $date = '0000-00-00';
$entry=mysql_real_escape_string($_POST['entry']);
$query = "INSERT INTO blog VALUES ('','$title','$date','$entry')";
mysql_query($query) or die('Problem with insert query: ' . $query . '<br />' . mysql_error());
?>[/code]

The date checking code will allow your users to input any valid date. (not tested)

Ken
[/quote]


cool I'll add what you mentioned and see what I end up with.
Link to comment
Share on other sites

Is it possible there could be something wrong with my MySQL isntallation? I've never had this problem before. I tried what was mentioned here and it didnt help. the I downloaded a blog script from hotscripts to try and its the same with that as well. I'm relly stuck.
Link to comment
Share on other sites

[!--quoteo(post=354605:date=Mar 13 2006, 07:01 PM:name=rish1103)--][div class=\'quotetop\']QUOTE(rish1103 @ Mar 13 2006, 07:01 PM) [snapback]354605[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Is it possible there could be something wrong with my MySQL isntallation? I've never had this problem before. I tried what was mentioned here and it didnt help. the I downloaded a blog script from hotscripts to try and its the same with that as well. I'm relly stuck.
[/quote]

Probably not.. if you can connect to your database there's not a problem..

Please replace the following with your mysql_query and repost the results:

[code]mysql_query($query) or die('Problem with insert query: ' . $query . '<br />' . mysql_error());[/code]

Hopefully this will give us a more accurate guess as to what the problem is! [=

GOOD LUCK!

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.