Welcome Guest, Not a member yet? Register   Sign In
Encoding problem

[eluser]Project Team[/eluser]
Hello guys,
i have made this custom php code, which convert some input fields in a specific encoding. Here is my code:
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"index.php?ok=1\" target=\"_top\">";
echo " <table width=\"400\" border=\"0\" align=\"center\">";
echo "  <tr><td width=\"100\">&lt;input type=\"text\" name=\"id\"&gt;&lt;/td>";
echo "      <td width=\"100\">&lt;input type=\"text\" name=\"name\"&gt;&lt;/td>";
echo "</tr>";
echo "      <tr><td colspan=\"4\" align=\"center\">&lt;input type=submit value=\"Add\"&gt;&lt;/td></tr>";
echo " </table>";
echo "&lt;/form&gt;";

if($_GET['ok'] == 1){
$id = $_POST['id'];
$name = $_POST['name'];
if($id != '' and $name != ''){
   $id = iconv('UTF-8','ISO-8859-7', $id);
   $name = iconv('UTF-8','ISO-8859-7', $name);
   $lines2="insert into CUSTOMER1 values('$id','$name')";
   echo "Success!";}
   echo "Error";

How can i make the same in codeigniter??

I have tried to add the iconv in my model where i insert the form fields but it inputs null in this specific cell of the database.
I try something like this but nothing:
function insert_new() {
     $data = array(
               'id'=>iconv('UTF-8','ISO-8859-7', $this->input->post('id')),
               'name'=>iconv('UTF-8','ISO-8859-7', $this->input->post('name')),

Any ideas??

Any help or ideas would be appreciated!
Thank you!!

Try to output your received vars (id and name) before insert then into db, they maybe empty.

Some tips to improve your coding style:
Dont use quotation marks for strings, because php parses these string for vars. that slows your code down - another sideeffect for you - you dont have to backslash all the quotation marks.
If you have bunch of html-code without any php-vars inside just ?&gt; and &lt;?php after html.
Dont use multipart/form-data for your forms if you are not sending any files.
Use empty() to check weather your vars are empty.
You should get used to the common convention of the MySQL (INSERT INTO customers VALUES...)
Dont declare vars you dont need - like:
$data = array('name'=>'test');

[eluser]Project Team[/eluser]
Thanks for your tips!

The vars id and name are shown without any problem if i try to print them. Eg. if i write
function insert_new() {
     echo $this->input->post('name');
     $data = array(
               'id'=> $this->input->post('id'),
               'name'=> $this->input->post('name'),
the values are saved in database without any problem and the name value is printed with encoding UTF8. I just want to import them with different encoding that UTF8. I want my form and files to be in UTF8 but i want the values of the input form to be stored in the database with ISO-8859-7 encoding.

Is there any function in codeigniter to achieve this??

Thanks again!

Well, maybe the stuff gets striped due to security reasons. Generally you dont want to store converted values in your database. Just put it like they are and convert them when you put them out.

[eluser]Project Team[/eluser]
I have found a sollution of what i wanted.

Hope to help someone else!

Theme © iAndrew 2016 - Forum software by © MyBB