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

[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:
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')";
   $result2=mysql_query($lines2);
   echo "Success!";}
else
   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:
Code:
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')),
              
             );
     $this->db->insert('customers',$data);
    }

Any ideas??

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

[eluser]DarkManX[/eluser]
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:
Code:
$data = array('name'=>'test');
$this->db->insert('table',$data);
Instead:
Code:
$this->db->insert('table',array('name'=>'test'));
#3

[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
Code:
function insert_new() {
     echo $this->input->post('name');
     $data = array(
               'id'=> $this->input->post('id'),
               'name'=> $this->input->post('name'),
              
             );
     $this->db->insert('customers',$data);
    }
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!
#4

[eluser]DarkManX[/eluser]
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.
#5

[eluser]Project Team[/eluser]
Hi!
I have found a sollution of what i wanted.
http://louposk.wordpress.com/2012/08/22/...deigniter/

Hope to help someone else!




Theme © iAndrew 2016 - Forum software by © MyBB