Reply
How to Encode / Decode through a form
Old 06-05-2008, 02:32 PM How to Encode / Decode through a form
Experienced Talker

Posts: 34
Name: Jin
Location: Bangkok
How can I except different languages through a form and store it in a MySQL database to be displayed on the website after?

I have 2 databases with 2 different scripts, one database can take multiple languages and store, display it with no problem but the other can not, this tells me since both databases and scripts are on the same server the difference has to be in the form submission method but I have looked through the files and do not see anything that would tell me how one is doing it and the other isn't.

An example is if I want to submit Thai language in a form สวัสดีครับ the encode would look like this in a database
PHP Code:
สวัสดีครับ 


Then the output to the page would get decoded back to the recognizable Thai language.

Anybody can point me to any information on how this can be done?

I am using MySQL 5+ UTF-8
Thai Freelance is offline
Reply With Quote
View Public Profile Visit Thai Freelance's homepage!
 
When You Register, These Ads Go Away!
Old 06-05-2008, 03:22 PM Re: How to Encode / Decode through a form
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
Errm Thai is a multi-byte language you'd need UTF-16. Also make sure your files are saved in and have the encoding listed as, UTF-16. Can I see both your scripts though?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-05-2008, 03:57 PM Re: How to Encode / Decode through a form
Experienced Talker

Posts: 34
Name: Jin
Location: Bangkok
Thats what I am trying to find out how to do, how do I save it with encoding listed? Not sure what I should be looking for or what needs to be changed.

What is it that you want to see in the scripts? I can post some code here if you let me know what it is that you will need to see?

Thanks

Quote:
Errm Thai is a multi-byte language you'd need UTF-16. Also make sure your files are saved in and have the encoding listed as, UTF-16. Can I see both your scripts though?
Thai Freelance is offline
Reply With Quote
View Public Profile Visit Thai Freelance's homepage!
 
Old 06-05-2008, 06:05 PM Re: How to Encode / Decode through a form
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
<meta http-equiv="Content-Type" content="text/html; charset=UTF-16">
Add that right after the head tag. With your scripts I just want to see the form itself and the section that holds the insert statement to see if maybe I can spot anything going on.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-05-2008, 09:41 PM Re: How to Encode / Decode through a form
nyef's Avatar
Ultra Talker

Posts: 267
Name: Lucas
Take a look at the <form> tag on both pages and make sure they are exactly the same
__________________
~nyef
Over 5000 free games!
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-06-2008, 02:00 AM Re: How to Encode / Decode through a form
Experienced Talker

Posts: 34
Name: Jin
Location: Bangkok
Both scripts have the same meta tag in them as the one below. If I am not mistaken this will not help in a form submission but it tells the search engines what language your page is in.

Code:
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
This is the form that does not work
HTML Code:
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="form123" id="form123" onSubmit="return validate(this);">
  <table width="90%" border="0" align="center" cellpadding="2" cellspacing="2" class="onepxtable">
    <tr class="titlestyle"> 
      <td colspan="3">&nbsp;Bidding for <font class="red"><strong><?php echo $sbrow_pro["sb_title"] ?></strong></font></td>
    </tr><?php  if(!isset($_SESSION["sbprj_userid"]))
 { ?>
    <tr valign="top"> 
      <td width="40%" align="right" class="innertablestyle"><font class="normal"><strong>Username 
        </strong></font></td>
      <td><font class="red">*</font></td>
      <td><font face="Arial, Helvetica, sans-serif" size="2"> 
        <input name="sb_username" type="text"   id="sb_username" value="<?php echo $sb_username; ?>" size="30" maxlength="30">
        </font></td>
    </tr>
    <tr valign="top"> 
      <td height="24" align="right" class="innertablestyle"><font class="normal"><strong>Password</strong></font></td>
      <td><font class="red">*</font></td>
      <td><font face="Arial, Helvetica, sans-serif" size="2"> 
        <input name="sb_password" type="password"  id="sb_password" size="30" maxlength="30" >
        </font></td>
    </tr><?php  } //end if  if(!isset($_SESSION["sbprj_userid"]))
?>
    <tr valign="top"> 
      <td width="40%" align="right" class="innertablestyle"><font class="normal"><strong>Bid 
        Amount </strong></font></td>
      <td width="6"><font class="red">*</font></td>
      <td width="60%"><font class="normal"><?php echo $sb_fee_currency; ?></font><font face="Arial, Helvetica, sans-serif" size="2">
        <input name="sb_bidamt" type="text"   id="sb_bidamt" value="<?php echo $sb_bidamt; ?>" size="15" maxlength="30">
        </font></td>
    </tr>
    <tr valign="top"> 
      <td height="24" align="right" class="innertablestyle"><font class="normal"><strong>Completion 
        Time </strong></font></td>
      <td><font class="red">*</font></td>
      <td><font class="normal"> 
        <input name="sb_timelimit" type="text"  id="sb_timelimit"  value="<?php echo $sb_timelimit; ?>" size="15" maxlength="30" >
        Days </font></td>
    </tr>
    <tr valign="top"> 
      <td height="24" align="right" class="innertablestyle"><font class="normal"><strong>Comments</strong></font></td>
      <td><font class="red">*</font></td>
      <td><font class="smalltext"> 
        <textarea name="sb_comments" cols="40" rows="8" id="sb_comments"><?php echo $sb_comments; ?></textarea>
        <?php if($sb_comment_len>0) {?>
        <br>
        <font class="smalltext">not more than <?php echo $sb_comment_len; ?> 
        characters</font> 
        <?php }  //end if ?>
        </font></td>
    </tr>
    <tr valign="top"> 
      <td align="right" class="innertablestyle">&nbsp;</td>
      <td>&nbsp;</td>
      <td><input name="sb_notify" type="checkbox" id="sb_notify" value="yes" <?php echo($sb_notify=='yes')?'checked':''?>> 
        <font class="normal">Notify me.</font></td>
    </tr>
    <tr valign="top"> 
      <td align="right" class="innertablestyle">&nbsp;</td>
      <td>&nbsp;</td>
      <td><input name="submit"  type="submit" value="Bid Now">
        <input name="sb_id" type="hidden" id="sb_id" value="<?php echo $sb_id?>"></td>
    </tr>
  </table>
  </form>
This is the form that does work
PHP Code:
echo '<form method="POST" action="project.php">
<input type="hidden" name="bid" value="' 
$bid '">
<big><b>Bid on Project: ' 
SQLact("result"$result,0,"project") . '</b></big>
<p>
<p>
<strong>Username:</strong><br>
<small>(<a href="' 
$siteurl '/freelancers.php?new=user">Click here to signup</a>)</small>
<br>
<input type="text" name="username" value="' 
$username '" size="15">
<p>
<strong>Password:</strong><br>
<input type="password" name="password" value="' 
$password '" size="15">
<p>
<strong>Your bid for the total project:</strong><br>'
;
if (
SQLact("result"$result,0,"budgetmin") == "" && SQLact("result"$result,0,"budgetmax") !== "") {
echo 
'<small>Project budget maximum is ' $currencytype '' $currency '' SQLact("result"$result,0,"budgetmax") . '</small><br>';
} else if (
SQLact("result"$result,0,"budgetmin") !== "" && SQLact("result"$result,0,"budgetmax") == "") {
echo 
'<small>Project budget minimum is ' $currencytype '' $currency '' SQLact("result"$result,0,"budgetmin") . '</small><br>';
} else if (
SQLact("result"$result,0,"budgetmin") !== "" && SQLact("result"$result,0,"budgetmax") !== "") {
echo 
'<small>Project budget is ' $currencytype '' $currency '' SQLact("result"$result,0,"budgetmin") . ' - ' $currencytype '' $currency '' SQLact("result"$result,0,"budgetmax") . '</small><br>';
}
echo 
$currencytype '' $currency '<input type="text" name="bidamount" maxlength="6" size="6">
<p>
<strong>In how many days can you deliver a completed project?</strong><br>
<small>'
;
$secondsPerDay = ((24 60) * 60);
$timeStamp time();
$daysUntilExpiry SQLact("result"$result,0,"expires");
$expiry $timeStamp + ($daysUntilExpiry $secondsPerDay);
$date  getdate($expiry);
$month $date["mon"];
$day   $date["mday"];
$year  $date["year"];
$expiryDate $month '/' $day '/' $year;
echo 
'(The user wants the project completed by ' $expiryDate', which is ';
if (
$expiry==0) {
echo 
'in less than one day.)';
} else if (
$expiry>=1) {
echo 
'in ' . ( $expiry $timeStamp ) / $secondsPerDay ' day';
if (
$expiry==1) {} else {
echo 
's';
}
echo 
'.)';
} else {
echo 
'expired.)';
}
echo 
'</small>
<br>
<input type="text" name="days" maxlength="3" value="' 
. ( $expiry $timeStamp ) / $secondsPerDay '" size="5"> Day(s)
<p>
<strong>Provide the details of your bid (optional):</strong><br>
<textarea rows="8" name="details" cols="52"></textarea>
<p>
<input type="checkbox" name="outbid" value="y"> Notify me by e-mail if someone bids lower than me on this project.
<p>
<input type="submit" value="Place Bid" name="submit">
</form>'

Thai Freelance is offline
Reply With Quote
View Public Profile Visit Thai Freelance's homepage!
 
Old 06-06-2008, 05:19 PM Re: How to Encode / Decode through a form
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
What's the PHP that processes them both?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-10-2008, 12:54 AM Re: How to Encode / Decode through a form
Experienced Talker

Posts: 34
Name: Jin
Location: Bangkok
Sorry for late reply

This is the complete form that does not work
PHP Code:
<?
 
if(!isset($_SESSION["sbprj_userid"]))
 {
  
$sb_username='';
  
$sb_password='';
  
$sb_empty=false;  //used to check whether some input was there or not 
  
if( !isset($_REQUEST["sb_username"]) || ($_REQUEST["sb_username"]=='') )
  {
   
$sb_empty=true;
   
$errs[$errcnt]="Username must be provided";
   
$errcnt++;
  }
  else
   
$sb_username=$_REQUEST["sb_username"];
 
  if( !isset(
$_REQUEST["sb_password"]) || ($_REQUEST["sb_password"]=='') )
  {
   
$sb_empty=true;
   
$errs[$errcnt]="Password must be provided";
   
$errcnt++;
  }
  else
   
$sb_password=$_REQUEST["sb_password"];
  if(!
get_magic_quotes_gpc())
  {
   
$sb_username=str_replace("$","\$",addslashes($sb_username));
   
$sb_password=str_replace("$","\$",addslashes($sb_password));
  }
  else
  {
   
$sb_username=str_replace("$","\$",$sb_username);
   
$sb_password=str_replace("$","\$",$sb_password);
  }
 
  include_once
'loginfun.php';
  
$sb_userid=loginuser($sb_username,$sb_password,false);  //third arg is cool chk it
  
if(  !$sb_empty && ($sb_userid == ) )
  {
   
$errs[$errcnt]="Webmaster can't bid for the project";
   
$errcnt++;
  }
  elseif(  !
$sb_empty && ($sb_userid 1) )
  {
   
$errs[$errcnt]="Username/Password is incorrect";
   
$errcnt++;
  }
 } 
//end if !isset($_SESSION["sbprj_userid"])
 
else
 {
  include_once
'programmer_include.php';
  
$sb_userid=$_SESSION["sbprj_userid"];
  if(!
get_magic_quotes_gpc())
   
$sb_username=str_replace("$","\$",addslashes($_SESSION["sbprj_username"]));
  else
   
$sb_username=str_replace("$","\$",$_SESSION["sbprj_username"]);
 }
 
$sb_notify='no'
 if( isset(
$_REQUEST["sb_notify"]) && ($_REQUEST["sb_notify"]=='yes') )
  
$sb_notify='yes';
 
 if( !isset(
$_REQUEST["sb_bidamt"]) || !is_numeric($_REQUEST["sb_bidamt"]) || ($_REQUEST["sb_bidamt"] <= 0) )
 {
  
$errs[$errcnt]="Bid Amount must be a non-zero positive number";
  
$errcnt++;
 }
 else
  
$sb_bidamt=$_REQUEST["sb_bidamt"];
 if( !isset(
$_REQUEST["sb_timelimit"]) || !is_numeric($_REQUEST["sb_timelimit"]) || ($_REQUEST["sb_timelimit"] < 0) )
 {
  
$errs[$errcnt]="Completion Time must be a positive number";
  
$errcnt++;
 }
 else
  
$sb_timelimit=$_REQUEST["sb_timelimit"];   
/* $NULLNOTE|ZY-|WST| 
if(!isset($kvozewdva))
{ die();}   
*/ 
 
if( !isset($_REQUEST["sb_comments"]) || ( strlen(trim($_REQUEST["sb_comments"])) == 0) )
 {
  
$errs[$errcnt]="Comments must be provided";
  
$errcnt++;
 }
 elseif(
preg_match ("/[&<>]/"$_REQUEST["sb_comments"]))
 {
  
$errs[$errcnt]="Comments must not contain any special character i.e. < > &";
     
$errcnt++;
 }
 elseif( (
$sb_comment_len 0) && (strlen(trim($_REQUEST["sb_comments"])) > $sb_comment_len) )
 {
  
$errs[$errcnt]="Comments can't be more than $sb_comment_len characters long";
     
$errcnt++;
 }
 else
  
$sb_comments=trim($_REQUEST["sb_comments"]);
 if(
$errcnt==0)
 {
  if(!
get_magic_quotes_gpc())
  {
   
$sb_comments=str_replace("$","\$",addslashes($_REQUEST["sb_comments"]));
  }
  else
  {
   
$sb_comments=str_replace("$","\$",$_REQUEST["sb_comments"]);
  }
 if(
$sb_bid_approval=='auto')
  {
  
$sb_approved_insert='yes';
  
$sb_approved="yes";
  
$msg="Your bid has been placed";
 }
 else
 {
  
$sb_approved_insert='new';
  
$sb_approved="no";
  
$msg="Your bid has been sent for admin approval";
 }
 
 
$sb_biddate=date("YmdHis",time());
 
 
$sbq_bid_chk="select * from sbprj_bids where sb_project_id=$sb_id and sb_userid=$sb_userid";
 
$sbrow_bid_chk=mysql_fetch_array(mysql_query($sbq_bid_chk));
 if(
$sbrow_bid_chk)
 {
  if(
$sbrow_bid_chk["sb_approved"]=='yes')
  {
   
$sbq_bid="update`sbprj_bids` set sb_bidamt=$sb_bidamt, sb_timelimit=$sb_timelimit, sb_comments='$sb_comments', sb_biddate=$sb_biddate, sb_approved='$sb_approved', sb_notify='$sb_notify' where sb_id=".$sbrow_bid_chk["sb_id"];
  }
  else
  {
   
$sbq_bid="update`sbprj_bids` set sb_bidamt=$sb_bidamt, sb_timelimit=$sb_timelimit, sb_comments='$sb_comments', sb_biddate=$sb_biddate, sb_notify='$sb_notify' where sb_id=".$sbrow_bid_chk["sb_id"];
   
$msg="Your bid has been sent for admin approval";
  }
 }
 else
  
$sbq_bid="insert into `sbprj_bids` (sb_project_id, sb_userid, sb_username, sb_bidamt, sb_timelimit, sb_comments, sb_biddate, sb_approved, sb_notify) values ($sb_id, $sb_userid, '$sb_username', $sb_bidamt, $sb_timelimit, '$sb_comments', $sb_biddate, '$sb_approved_insert', '$sb_notify')";
 
//echo $sbq_bid;
//die();
/* $NULLNOTE|ZY-|WST| 
if(!isset($kvozewdva))
{ die();}   
*/   
 
mysql_query($sbq_bid);
 if(
mysql_affected_rows()>0)
 {
  
$sbq_bid1="select * from `sbprj_bids` where sb_project_id=$sb_id and sb_userid=$sb_userid";
  
$sbrow_bid1=mysql_fetch_array(mysql_query($sbq_bid1));
 
//////---------sendin' mail to adm if approval type is admin
 
if( $sbrow_bid1["sb_approved"]<>'yes' )//$sbrow_con["sb_bid_approval"]=="admin") //for mailing
 
{
  
$sbq_mem="select * from sbprj_members where sb_id=$sb_userid";
  
$sbrow_mem=mysql_fetch_array(mysql_query($sbq_mem));
 
//  $sbrow_con=mysql_fetch_array(mysql_query("select * from sbprj_config"));
  
$sb_null_char=$sbrow_con["sb_null_char"];
  
$sb_site_root=$sbrow_con["sb_site_root"];
  
$sb_admin_email=$sbrow_con["sb_admin_email"];
  
$sb_project_url=$sb_site_root."/view_project.php?sb_id=$sb_id";
  
$sql "SELECT * FROM sbprj_mails where sb_mailid=6" ;
  
$rs_query=mysql_query($sql);
//  $login_url=$sb_site_root."/signin.php";
 
  
if ( $rs=mysql_fetch_array($rs_query)  )// if mail
  
{
   if(
$rs["sb_status"]=="yes"
    {
      
$from=$rs["sb_fromid"];
      
$to $sb_admin_email;
      
$subject =$rs["sb_subject"];
 
    
$body=str_replace("%email%"$sbrow_mem["sb_email_addr"],str_replace("%password%",$sb_null_charstr_replace("%fname%"$sbrow_mem["sb_firstname"],str_replace("%username%"$sbrow_mem["sb_username"], $rs["sb_mail"]) ))); 
 
  
$body=str_replace("%signup_url%",$sb_null_char,str_replace("%login_url%",$sb_null_char,$body));
 
  
$body=str_replace("%project_id%",$sb_id,