Hi all,
Wonder if anyone could shed some light on this strange problem. Its quite a smple form which posts to a small database containing only 3 fields.
It has been working fine but in the last couple of days some of the characters are displaying incorrectly.
Generally an apostrophe in the text or title is displaying as a ? on a mac machine and is a little square on a pc. There are other characters not displaying also, including, £ -
I have posted the code i have used for months below.
This is the code for posting the info to the database:
<?php
$host="localhost"; // Host name
$username="xxxxxxxx"; // Mysql username
$password="xxxxxxx"; // Mysql password
$db_name="xxxxxxxxx"; // Database name
$tbl_name="xxxxxxxxx"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$maintitle = addslashes($_POST['maintitle']);
$precis = addslashes($_POST['precis']);
$text = addslashes($_POST['text']);
// Insert data into mysql
$sql="INSERT INTO $tbl_name(maintitle, text, precis)VALUES('$maintitle', '$text', '$precis')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
And this is the code retrieving it from the database
<table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><br /><br /><p align="center" class="yeartitle">2008 NEWS REPORTS</p>
</td>
</tr>
<tr>
<td align="left" width="145"><p class="reportstitle">Date Posted </p></td>
<td align="left"><p class="reportstitle">Subject</p></td>
</tr>
<?php
// This is to connect to and open the database
$dbhost = 'xxxxxxxx';
$dbuser = 'xxxxxxxx';
$dbpass = 'xxxxxxx';
$dbname = 'xxxxxxxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query = "SELECT id, maintitle, DATE_FORMAT(date,'%a %D %M %Y ') as date FROM reports WHERE year='2008' ORDER by id DESC";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
#First print the opening tag...
while ($row = mysql_fetch_assoc ($result)) {
$id = $row['id'];
$maintitle = $row['maintitle'];
$date = $row['date'];
#this will print a new row for each photo..
echo "
<tr>
<td align=\"left\" width=\"170\"><p class=\"date\">$date </p></td><td align=\"left\"> <a href=\"viewall.php?id=$id\">$maintitle</p></td>
</tr> ";
}
// This is to close database
mysql_close($conn);
?>
</table>
I have contacted my host and they say that they havnt changed any settings or made any updates/upgrades that would cause this.
I am just frustrated now as it has been working fine for months.
Anyone got any ideas whats wrong, or suggestions on changing the code so this doesnt occur anymore.
Thanks in advance for taking the time to read this and post a reply.