PHP and MySql accents and ñ problems
Posted: Fri Jul 25, 2008 3:59 am
Hello first i would like to say hello to all the community since im new here 
second here is my problem...
I have a PHP news system i have made with a tutorial and i have a problem with adding news... when editing a new you can put accents on the news and even ñ but when i'm adding it, i mean adding a new one... it gives me error.
Here's my code...
Add news:
Edit news:
Messages are in spanish but i don't think that's a problem 
I tried changing mysql collation but it didn't work...
Thx in advance!!
second here is my problem...
I have a PHP news system i have made with a tutorial and i have a problem with adding news... when editing a new you can put accents on the news and even ñ but when i'm adding it, i mean adding a new one... it gives me error.
Here's my code...
Add news:
Code: Select all
<?php
include ('connect.php');
if (isset($_POST['submitted'])) {
if (empty($_POST['title'])) {
echo '<p><font color="red">Introduce un título válido.</font></p>';
} else {
$title = $_POST['title'];
}
if (empty($_POST['message'])) {
echo '<p><font color="red">Introduce un mensaje válido.</font></p>';
} else {
$message = $_POST['message'];
}
if ($title && $message) {
$query = "INSERT INTO news_posts (title, author, post, DATE) VALUES ('$title', '$nam', '$message', NOW())";
$result = mysql_query($query);
if ($result) {
echo '<p><font color="red">Noticia añadida!</font></p>';
echo '<a href="http://otakunosekai.es/index.php">Inicio.</a>';
} else {
echo '<font color="red"><p>Error, por favor inténtalo de nuevo.</p></font>';
}
} else {
echo '<p><font color="red">Introduce la información necesaria porfavor.</font></p>';
}
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><b>Título de la noticia :</b><br />
<input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>" /></p>
<p><b>Mensaje :</b><br />
<textarea rows="8" cols="55" name="message"><?php if(isset($_POST['message'])) echo $_POST['message']; ?></textarea></p>
<p><input type="submit" name="submit" value="Añadir" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>Code: Select all
include('connect.php');
if ((isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) {
$id = $_POST['id'];
} else {
echo 'Elige un post para editar primero.';
exit();
}
if (isset($_POST['submitted'])) {
$errors = array();
if (empty($_POST['title'])) {
$errors[] = 'Introduce un título válido.';
} else {
$title = $_POST['title'];
}
if (empty($_POST['message'])) {
$errors[] = 'Introduce un mensaje válido.';
} else {
$message = $_POST['message'];
}
if (empty($errors)) {
$query = "UPDATE news_posts SET title='$title', author='$nam', post='$message' WHERE id=$id";
$result = mysql_query($query);
if ($result) {
echo "Noticia actualizada!";
} else {
echo "Error, la noticia no se pudo actualizar.";
}
} else {
echo 'Multiples errores ocurrieron :<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
}
} else {
$query = "SELECT title, post, id FROM news_posts WHERE id=$id";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$title = $row['0'];
$message = $row['1'];
if ($num == 1) {
echo '<h3>Editar Noticia</h3>
<form action="?id=editarnoticias&num='.$id.'" method="post">
<p>Título : <input type="text" name="title" size="25" maxlength="255" value="'.$title.'" /></p>
<p>Mensaje : <br /><textarea rows="5" cols="40" name="message">'.$message.'</textarea></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
<input type="hidden" name="id" value="'.$id.'" />';
} else {
echo 'Error, por favor inténtalo de nuevo.';
}
}
?>I tried changing mysql collation but it didn't work...
Thx in advance!!