php - Column value's string length reduced by one when the value has a Quote -


hi have table "comments" , here has field called "comment_text" , insert comment table

   $query="insert `comments`      (`id`,     `comment_text`,      `date`)      values     ('',     '".sprintf("%-70s",mysql_real_escape_string(ucwords(trim($strtitle63_5))))."',     '$date')"; 

as can see setting comment length fix 70 characters (always original comment less 70 characters.)

everything works fine unless insert value quote , if insert comment quote , in database table can see 69 characters .

example :

i insert these 2 comments

comment 1 : "flat rate overlaps flat rate code"

comment 2 : "claim details don't match bsi/bri guidelines"

later when try check string length . comment 1 70 , comment 2 69. there reason ?

every comment has quote gives me issue . :( .

thanks in advance .

update

my code

model

function get_coc5_comment_details() {     $this->db->select("comment_text");     $this->db->from("comments");     $result=$this->db->get();      return $result->result_array(); } 

controller

function validate_db() {     $result = $this->invoice_model->get_comment_details();     $this->load->view("comment_details_view",array("result"=>$result)); } 

view

foreach ($result $row) {     $comment = $row['comment_text'];      echo strlen($comment)."<br>"; } 

everything works fine unless insert value quote , if insert comment quote , in database table can see 69 characters .

because when there quote in string , run through mysql_real_escape_string adds \ in string :)

and that's 1 character. once goes database \ removed , see 69.

why don't consider prepared statements?

also, storing spaces in database no reason @ not design. can write wrapper method display appends comments spaces complete 70 character length when using those. think should storing original comments in database. if day length requirement becomes 75 reason?

for example

$str="test"; echo str_pad($str, 70,'*');   // take 70 characters. 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -