Jump to content

Problem with search ... Bulgarian language


golemicata

Recommended Posts

I have 2 files:

search.html

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

  <title></title>

</head>

 

<body>

  <h1>***</h1>

 

  <form action="results.php" method="post">

    Choose Search Type:<br />

    <select name="searchtype">

      <option value="ItemType">артикул</option>

      <option value="size">размер</option>

    </select>

    <br />

    Enter Search Term:<br />

    <input name="searchterm" type="text">

    <br />

    <input type="submit" value="Search">

  </form>

 

</body>

</html>

 

and results.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

  <title>**** Резултати от търсенето</title>

</head>

<body>

<h1> - Резултати от търсенето</h1>

<?php

  // create short variable names

  $searchtype=$_POST['searchtype'];

  $searchterm=$_POST['searchterm'];

 

  $searchterm= trim($searchterm);

 

  if (!$searchtype || !$searchterm)

  {

    echo 'You have not entered search details.  Please go back and try again.';

    exit;

  }

 

  $searchtype = addslashes($searchtype);

  $searchterm = addslashes($searchterm);

 

  @ $db = mysql_pconnect('localhost', '***', '***');

 

  if (!$db)

  {

    echo 'Error: Could not connect to database.  Please try again later.';

    exit;

  }

 

  mysql_select_db('eshop');

  $query = "select * from item where ".$searchtype." like '%".$searchterm."%'";

  $result = mysql_query($query);

 

  $num_results = mysql_num_rows($result);

 

  echo '<p>Брой намерени артикули: '.$num_results.'</p>';

 

  for ($i=0; $i <$num_results; $i++)

  {

    $row = mysql_fetch_array($result);

    echo '<p><strong>'.($i+1).'. ItemType: ';

    echo htmlspecialchars(stripslashes($row['ItemType']));

    echo '</strong><br />size: ';

    echo stripslashes($row['size']);

    echo '<br />Price: ';

    echo stripslashes($row['price']);

    echo '</p>';

  }

?>

 

</body>

</html>

 

 

When I entered a Bulgarian letters in search box and press search button --> the message is Брой намерени артикули: 0 ( number of items found: 0 ) . In the database in column ItemType have a bulgarian language names. When I search in English - do not have a problem : Брой намерени артикули: 1 ( Numbers of items found: 1 )

1.ItemType: t-shirt

size: L

Price: 5.00

 

Can you help me?

 

 

Next problem is :    :(

 

 

newitem.html

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

  <title>****</title>

</head>

 

<body>

  <h1>***</h1>

 

  <form action="insert_item.php" method="post">

    <table border="0">

    <tr>

        <td>ItemID</td>

        <td><input type="text" name="ID" maxlength="190" size="190"><br /></td>

      </tr>

      <tr>

        <td>Вид артикул</td>

        <td><input type="text" name="ItemType" maxlength="63" size="63"><br /></td>

      </tr>

      <tr>

        <td>Размер</td>

        <td> <input type="text" name="size" maxlength="19" size="19"><br /></td>

      </tr>

     

      <tr>

        <td>Цена (лева)</td>

        <td><input type="text" name="price" maxlength="7" size="7"><br /></td>

      </tr>

      <tr>

        <td>Език ( 1 за BG, 2 за EN )</td>

        <td><input type="text" name="IDL" maxlength="2" size="2"><br /></td>

      </tr>

      <tr>

        <td colspan="2"><input type="submit" value="Register"></td>

      </tr>

    </table>

  </form>

</body>

</html>

 

 

insert_item.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

  <title>****</title>

</head>

<body>

<h1>****</h1>

<?php

  // create short variable names

 

  $ItemID=$_POST['ItemID'];

  $ItemType=$_POST['ItemType'];

  $size=$_POST['size'];

  $price=$_POST['price'];

  $IDL=$_POST['IDL'];

 

  if ( !$ItemType || !$size || !$price || !$IDL )

  {

    echo 'You have not entered all the required details.<br />'

          .'Please go back and try again.';

    exit;

  }

 

  $ItemID = addslashes($ItemID);

  $ItemType = addslashes($ItemType);

  $size = addslashes($size);

  $price = doubleval($price);

  $IDL = addslashes($IDL);

 

  @ $db = mysql_pconnect('localhost', '***', '**');

 

  if (!$db)

  {

    echo 'Error: Could not connect to database.  Please try again later.';

    exit;

  }

 

  mysql_select_db('eshop');

  $query = "insert into item values

            ('".$ItemID."','".$ItemType."', '".$size."',  '".$price."', '".$IDL."')";

  $result = mysql_query($query);

  if ($result)

      echo  mysql_affected_rows().' item inserted into database.';

?>

 

</body>

</html>

 

When I add an article with Bulgarian letters  (for exampe ?обувки?)  in my Database  in the column ItemType is  saved unknown symbols.  The Collation is utf8_general_ci.  And the columns ? price and size exchanged his values I don't want.  (the sequence in table is ItemID, ItemType, price, size, IDL )

When I manual insert a values into this table on my database do not have a problem with Bulgarian letters.

 

I don?t known why  ?

 

ItemID is auto increment not null and I wish when I add new item do not have to add ID, but when I remove it the item can not add to the database . PS: I wish don?t add a value in ItemId into html form and it?s automatically  add in the database.

When I removed ItemID  from results.php  and add a new item ---  nothing happens ?

 

 

Sorry for stupid questions but I'm new in this field.

 

Link to comment
https://forums.phpfreaks.com/topic/265516-problem-with-search-bulgarian-language/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.