Jump to content

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

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.