Jump to content

problems with "SET NAMES 'utf8'" not working in select list for non latin


Recommended Posts

im using

<?php mysql_query("SET NAMES 'utf8'")?>

 

i want the select list to show country names in  hebrew for example on this page:

<?php require_once('../Connections/international.php'); ?>
<?php $CatID=intval($_GET['CatID']);
header('Content-type: text/html; charset=UTF-8') ;
?>
<?php mysql_query("SET NAMES 'utf8'")?>

<?php
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com

?>


<?php


$dbconnection = mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("international", $dbconnection) or die("Couldn't open database: ".mysql_error());


if (isset($CatID)) {
    
}
switch ($CatID)
{

   case 0:
   $result = mysql_query("SELECT country_list.CountryID,country_list.CountryName,country_list.CountryName_heb from country_list WHERE CategoryID = '".$_GET['CatID']."'");
break;

    case 1:
$result = mysql_query("SELECT country_list.CountryID,country_list.CountryName,country_list.CountryName_heb from country_list WHERE CategoryID = '".$_GET['CatID']."'");

        break;
    case 2:
        $result = mysql_query("SELECT country_list.CountryID,country_list.CountryName,country_list.CountryName_heb from country_list WHERE CatID2 = '".$_GET['CatID']."'");
        break;
case 3:
        $result = mysql_query("SELECT country_list.CountryID,country_list.CountryName,country_list.CountryName_heb from country_list WHERE CatID3 = '".$_GET['CatID']."'");
        break;
case 4:
        $result = mysql_query("SELECT country_list.CountryID,country_list.CountryName,country_list.CountryName_heb from country_list WHERE CatID4 = '".$_GET['CatID']."'");
        break;
case 5:
        $result = mysql_query("SELECT country_list.CountryID,country_list.CountryName,country_list.CountryName_heb from country_list WHERE CatID5 = '".$_GET['CatID']."'");
        break;

}   	

$row_result = mysql_fetch_assoc($result);
$totalRows_result = mysql_num_rows($result);

?>




<select name="state" onchange="getCity(<?php echo $CatID;?>,this.value)" width="220px">
<option>בחרו</option>
<?php while($row_result=mysql_fetch_assoc($result)) { ?>

<option value="<?php echo  $row_result['CountryID']; ?>"><?php echo $row_result['CountryName_heb']; ?></option>
<?php } ?>
</select>

<?php
mysql_free_result($result);
?>

Well for one, you are not connecting to the Database first. You are connecting after. If you were to have:

 

<?php mysql_query("SET NAMES 'utf8'") or trigger_error("Query Failed (UTF8): " . mysql_error()); ?>

 

It would probably tell you as such. Put that after you make the connection and select the database and it should work. If that is not what you are after, please elaborate on how it is not working.

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.