Jump to content

[SOLVED] Inserting long text to mysql


tradet

Recommended Posts

Now I'm having trouble inserting long texts into my mysql database.

 

It works fine through phpmyadmin so I don't think it's because of my database.

 

Here's my code:

<?php 
session_start();
if(!session_is_registered("login"))
header("location:login.php");

virtual('/Connections/bumhome.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/mainbumleft.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Bumhunter.net - new post</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="/styles/generalbumleft.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
</head>

<body>
  <div id="header"><a href="/index.php"><img src="/images/bimbum/1copygd0.jpg" alt="banner" /></a></div>
<!-- InstanceBeginEditable name="links" -->
  <div id="links">
    <div id="side_top">
      <div class="side"> <a href="/index.php">Home</a></div>
   	  <?php virtual('/includes/recent4.php'); ?>
    </div>
    <?php virtual('/includes/resources.php'); ?>
  	<?php virtual('/includes/quicklinks.php'); ?>
    <?php virtual('/includes/archive.php'); ?>
    <?php virtual('/includes/completearchives.php'); ?>
    <?php virtual('/includes/adminlinks.php'); ?>
  </div>
<!-- InstanceEndEditable -->
  <div id="content">
  	<!-- InstanceBeginEditable name="main" -->    
    <div class="blogbody">
    	<form action="/scripts/newpost.php" method="post">
    	    <p>Title:<br />
    	      <label>
   	          <input name="fTitle" type="text" id="fTitle" accesskey="m" tabindex="1" size="50" />
   	          </label>
    	      <br />
    	      <br />
    	      Post:<br />
    	    <div class="bbcode"><div class="quote"></div>, <div class="code"></div>, <img src="..."  />, <a href="...">link</a></div>
<br />
              <textarea name="fText" id="fText" cols="90" rows="20" accesskey="t" tabindex="2"></textarea>
    	      <input name="fDate" type="hidden" id="fDate" value="<?php $bogus = mysql_query("SELECT id FROM blog", $bumhome); echo date('Y-m-d G:i:s'); ?>" />
   	        </p>
    	    <br />
    	    <label>
    	    <input type="submit" name="fSubmit" id="fSubmit" value="Submit" accesskey="k" tabindex="3" />
   	      </label>
    	    <label>
    	    <input type="reset" name="fReset" id="fReset" value="Reset" />
    	    </label>
   	  </form>
    </div>
<!--
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
//-->
  	<!-- InstanceEndEditable -->
    <div id="footer">
    <div id="design">
    	Content (c) 2008 Jonas Hietala
    </div>
    </div>
</div>
</body>
<!-- InstanceEnd --></html>

 

And the insert script:

<?php 
session_start();
if(!session_is_registered("login")) {
header("location:login.php");
exit;
} else {
header('refresh: 0; url=../index.php');
}
virtual('/Connections/bumhome.php');

$title = $_POST['fTitle'];
$entry = $_POST['fText'];
$date = $_POST['fDate'];

$title = strip_tags(trim($title));
$entry = nl2br(trim($entry));

mysql_select_db($database_bumhome, $bumhome);
$query = "INSERT INTO blog (id, title, entry, date_entered)
VALUES ('0', '$title', '$entry', '$date')";
mysql_query($query, $bumhome);
?>

 

It works fine with shorter text.

Link to comment
Share on other sites

What do mean by "long text"? How long? Do you get any errors? What happens if you do

<?php
$query = "INSERT INTO blog (id, title, entry, date_entered)
VALUES ('0', '$title', '$entry', '$date')";
mysql_query($query, $bumhome) or die("Problem with the query: $query<br />" . mysql_error());
?>

 

You really should be using mysql_real_escape_string() on all the values you're inserting into the database. Do not trust user input:

<?php
$title = $_POST['fTitle'];
$entry = $_POST['fText'];
$date = mysql_real_escape_string($_POST['fDate']);

$title = mysql_real_escape_string(strip_tags(trim(stripslases($title))));
$entry = mysql_real_escape_string(trim($entry));
?>

 

Don't use nl2br() when inserting data into the database -- only use it when displaying data.

 

Ken

 

 

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.