Jump to content

PHP/MYSQL Does not save long data


sparky

Recommended Posts

I have an issue as to where I am trying to save long amounts of data into a database, and nothing that I try seems to work.... The field $detail when I have more than a coupld lines of data just does not write the data... Note code below:

 

Viewing the $SQL Data all shows correct... Just does not write it to the Database. I have tried changing to blob and other selections in the MYSQL, but not seeing what I am doing wrong. thanks in advance for any advice.

 

John

 

Database:

----------------------

-- phpMyAdmin SQL Dump
-- version 3.5.0
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 06, 2014 at 09:30 AM
-- Server version: 5.5.23
-- PHP Version: 5.3.13

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `elsa`
--

-- --------------------------------------------------------

--
-- Table structure for table `timeline2`
--

CREATE TABLE IF NOT EXISTS `timeline` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mo` text,
  `mon` text,
  `da` text,
  `yr` text,
  `hdr` text,
  `detail` longtext,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='Elsa Time Line' AUTO_INCREMENT=4 ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

 

 

----------------------

 

Insert Code:

----------------------

 

<?php
// open the connection
$conn = mysql_connect("localhost", "xxxx", "xxxx");

// pick the database to use

mysql_select_db("elsa",$conn);

// create the SQL statement

$mo=$_POST[mo];
$mon=$_POST[mon];
$da=$_POST[da];
$yr=$_POST[yr];
$hdr=$_POST[hdr];
$detail=$_POST[detail];

$sql = "INSERT INTO timeline2(mo, mon, da, yr, hdr, detail) values ('$mo', '$mon', '$da', '$yr', '$hdr', '$detail')";

echo $sql;
echo "<BR>";


// execute the SQL statement
if (mysql_query($sql, $conn)) {
        echo "Record Updated!";
} else {
        echo "Something went Wrong";
}

?>

----------------------

Example data that does not work.

----------------------

 

  <P ALIGN=CENTER>
   Elsa's Journey to her new home in Memphis</P>
  <CENTER>
   <P ALIGN=CENTER>
    <iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="510" src="http://www.youtube.com/embed/EJufDyBse8s" frameborder="0" allowFullScreen></iframe></P>
   </CENTER>
  <P ALIGN=CENTER>
   <!-- $MVD$:spaceretainer() --> </P>
  <P ALIGN=CENTER>
   Elsa at Home</P>
  <P ALIGN=CENTER>
   <A HREF="assets/140131/index.htm"><IMG SRC="assets/140131/elsa-013114-01_std.jpg" WIDTH="536" HEIGHT="800" VSPACE="0" HSPACE="0" BORDER="0">
<BR>
Click on IMAGE
</A></P>
  <P ALIGN=CENTER>
   <!-- $MVD$:spaceretainer() --> </P>
  <P ALIGN=CENTER>
   Elsa VS the Video Camera.</P>
  <CENTER>
   <P ALIGN=CENTER>
    <iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="510" src="http://www.youtube.com/embed/DTWntrEVuUs" frameborder="0" allowFullScreen></iframe></P>
   </CENTER>
  <P ALIGN=CENTER>
   A Very long Day for just a little Kitty...</P>
  <P ALIGN=CENTER>
   <IMG SRC="assets/140131/Sleeping.jpg" WIDTH="640" HEIGHT="480" VSPACE="0" HSPACE="0" BORDER="0"></P>
  <P ALIGN=CENTER>
   She was laying under her cat tree... When I turned off the lights
   (from remote) she got up and went to her cat bed and fell asleep.</P>

Edited by sparky
Link to comment
Share on other sites

i'll assume you are getting your "Something went Wrong" message?

 

you are not escaping your string data before putting it into the query statement, so all the characters like - ', ", \t, \r, \n that are in the data are breaking the sql syntax.

 

you need to use mysql_real_escape_string() on all string data being put into a query statement that can contain any characters that have meaning in the sql query or you need to use prepared query statements.

 

you also need to switch to the mysqli or pdo database library functions. the msyql functions are depreciated in php5.5 and you don't want to have to rewrite your code later when the mysql functions are removed.

Link to comment
Share on other sites

  • 2 weeks later...
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.