Jump to content

Weird chars on insert


choy

Recommended Posts

hello! i have a big trouble inserting data in mysql

 

i have a method called InsertData

 

public function InsertData($keys ,$values,$table)

{

 

$this->init(); //initialize the conn and stuff

$valueStr="";

 

//query construction

 

$sql = "INSERT INTO $table (";

 

foreach ($keys as $key) {

    $valueStr.= $key .",";

}

 

$valueStr = substr($valueStr,0,strlen($valueStr)-1);

$sql .= $valueStr . ") VALUES (";

$valueStr ="";

 

foreach ($values as $value) {

 

if (!is_numeric($value))

{

$value = "'" .$value ."'";

}

    $valueStr.= $value.",";

}

 

$valueStr = substr($valueStr,0,strlen($valueStr)-1);

$sql .= $valueStr . ")" ;

 

 

//echo $sql; echo mysql_error();

$success =  mysql_query($sql, $this->conn) or $success=0 ;

 

return $success;

}

 

if i try to insert some data like  "Adrián"...  the query insert other characters (like "adrían34")

 

i called the function this way

 

 

 

$keys[] ="name";

$keys[] = "descripction";

$values [] = $_GET["txtName"];

$values [] = $_GET["txtDesc"];

 

 

 

 

$ob->InsertData($keys ,$values,"division");

 

 

 

 

i thought that the problem  was the array that i passed to the function with the data....  BUT  when i print the query it appears like this

 

 

"INSERT INTO division (name,description) VALUES ('adrián','adrián') "

 

and then... the query are executed and the  value is all chunk

 

i tried to change the  columns encodings  and the headers but nothings work...

 

please help me im  so desperate

 

 

 

choy

 

:D

 

 

Link to comment
https://forums.phpfreaks.com/topic/70836-weird-chars-on-insert/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.