Hello to everyone, I´m having problems on retrieving data from mysql to a textfield in html, the data appears with queston marks inside of a "black diamond"! I researched and followed the steps like putting the database charset utf8, the table too! When I insert for example Alimentação its goes to the database like this and when i show it with a table made in php! but when i try do retrieve the data to another php page into textfields in html code, it substituts ção by queston marks inside of a "black diamond". When, again, I put this code

mysql_set_charset('utf8',$link);

in my php file to connect do the database, the problem inverts! the showing of the data gets strange characters and the data on the textfields gets like its should be, like this Alimentação.

This is the only php file that this happends, the html meta tag is UTF- 8 database too! Don' know what to do! I read the this symbols refer to the sequences of corrupted byte code and the the browser can identify the character so it puts this symbol.

Heres the code that is for showing the data and its ok on page1.php:

<?php
 //echo $got_id['id_user'];

echo "<table class='imagetable' align='center' border='1'><tr><th>Date</th><th>Merchant</th><th>Category</th><th>Amount</th><th>Notes</th></tr>";
while ($row = mysql_fetch_array($query_table_display)){
    echo "<tr>";
    for($i=2;$i<7;$i++){
        echo "<td>".$row[$i]."</td>"; 
    }
    echo '<td><a href="expenses_delete.php?id_expense='.$row['id_expense'].'">DELETE</A>'; 

    echo '<td><a href="expenses_edit_page.php?id_expense='.$row['id_expense'].'">EDIT</A>';//this link send me to the page2.php, to edit the seleceted row, with the respective id of the row
    ?>
     <?php

    echo "</tr>";
}
echo "</table>";
?>

heres the code from page2.php that is not ok without this mysql_set_charset('utf8',$link);

 <?php
    if(isset($_GET['id_expense'])){
    $query=mysql_query("SELECT * FROM expenses WHERE id_expense='".$_GET['id_expense']."'");
    $res=mysql_query($query);
    $to_edit=mysql_fetch_array($res,MYSQL_ASSOC);
?>
<form action="expenses_update.php" method="post" name="expense_edit">
    <tr>
 <div align="center">
 <table width="306" border="0" align="right">
  <tr>
    <td>&nbsp;</td>
    <td width="196"></td>
  </tr>
  <tr>
    <td width="98">Date</td>
    <td><label for="textfield"></label>
      <input type="text" name="date" value= "<?php echo $to_edit[2];?>" id="date_expense_id"></td>
      </tr>
  <tr>
    <td>Merchant</td>
    <td><label for="textfield2"></label>
      <input type="text" name="merchant" value="<?php echo html_entity_decode($to_edit[3]);?>" id="textfield2"></td>
    </tr>

    <tr>
      <td>Create a new category</td>
      <td colspan="2"><input type="text" name="category" value="<?php echo $to_edit[4];?>" id="id_category"></td>
      </tr>
    <tr>
    <td>Category</td>
    <td colspan="2"> <select name="expenses"  id="id_expense">
      <option value="0" selected="selected"> Choose</option>
      <?php
     while($row = mysql_fetch_assoc($query_column)){
        //$id=$row["id_expense"];  
        $category = $row["category_name"];
    ?>
      <option value= "<?php echo $category ?>" > <?php echo  $category ?> </option>
      <?php
      }
      ?>
      </select></td>
    </tr>

  <tr>
    <td>Amount</td>
    <td><label for="textfield4"></label>
      <input type="text" name="amount" value="<?php echo $to_edit[5];?>" id="textfield4"></td>
    </tr>
  <tr>
    <td>Notes</td>
    <td><label for="textarea"></label>
      <textarea name="notes" wrap="hard" id="textarea" value="<?php echo $to_edit[6];?>" cols="30" rows="5"></textarea></td>
  </tr>
  <tr>
    <td colspan="3">
      <input type="submit" name="button" id="button" value="Submit">
    </td>
    </tr>
</table>
  </div>
      <input type="hidden" name="id_expense" value="<?php  echo $_GET['id_expense'];?>" />
      </p>
</form>
    </td>
  </tr>

 <tr>
    <td height="253" colspan="4">&nbsp;</td>
  </tr>
</table>

Hello to all I managed to get this ok.For those of may have the same problem heres what I did for removing the questions marks in black diamond shapes and other strange characters.
In the php file where I had the code to insert and displaying mysql etc.I inserted this

if(!$link){
    die('Not possible!'.mysql_error());//report any error
}
    mysql_select_db('pap',$link);
    mysql_set_charset('utf8',$link);//this preventes the appearing of the strange characters

I had this code in a connect_database.php file and for any file i just needed to do include "connect_database.php" but for those files that presented me this characters I had to remove this include and had the code above. Thank you all who tried to solve this question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.