Bienvenido a datoweb.com!! En este foro podrás encontrar ayuda sobre diseño y desarrollo web en general. Si quieres formar parte de esta comunidad para pedir ayuda o colaborar ayudando a otros usuarios del foro solo tienes que registrarte desde el siguiente enlace: Registrarse en el Foro

Ayuda no puedo utilizar acentos ni ñ en el título

Hola he atravesado con este problema en más de una ocasión, cuando estoy creando un Post al momento de insertar el título del post, no puedo utilizar acentos ni la letra ñ puesto que al momento de publicar el post queda cortado el título justo donde se encuentra el acento o la ñ...no se si alguien me pueda echar una mano...gracias!!!
0
Puntos
1802
Visitas
6
Resp
Por RodrigoS hace 114 meses
Principiante
Respuesta #1
prueba usando la función GetSQLValueString, te pongo un ejemplo:
<?php require_once('../conexion.php');
if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
	{
	  if (PHP_VERSION < 6) {
		$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
	  }
	
	  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
	
	  switch ($theType) {
		case "text":
		  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
		  break;    
		case "long":
		case "int":
		  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
		  break;
		case "double":
		  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
		  break;
		case "date":
		  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
		  break;
		case "defined":
		  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
		  break;
	  }
	  return $theValue;
	}
}


$insertSQL = sprintf("INSERT INTO posts (titulo) VALUES (%s)",
	
	                    //GetSQLValueString -----------------------
						GetSQLValueString($_POST['titulo'], "text"));
					   

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

?>
0
Puntos
Por alber hace 114 meses
Administrador
Respuesta #2
también puedes poner aquí tu código para que revisemos donde esta el posible fallo
0
Puntos
Por alber hace 114 meses
Administrador
Respuesta #3
alber dijo:
también puedes poner aquí tu código para que revisemos donde esta el posible fallo
O tambien puden formato de caracteres en el php
por ejemplo si teneis un archivo functiones o functions.php o donde este todas las functiones basicas de tu web la injectarias ahi en esa pararte del codigo donde terminaria la consulta capas en este pequeño fragmento de codigo ya te andaria
espero que te functione
//FORMATO DE CARACTERES
    header('Content-Type: text/html; charset=iso-8859-1'); 
Saludos!
0
Puntos
Por fc2014 hace 114 meses
Experto
Respuesta #4
Aqui les dejo el codigo del archivo agregar.php
<?php require_once('Connections/conexion.php');
include("Includes/Proteger.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO post (Titulo, SEO, Keywords, Descripcion, Mensajes, Categoria, Autor, Fecha) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Titulo'], "text"),
GetSQLValueString(Limpia_Espacios($_POST['Titulo']), "text"),
GetSQLValueString(keywords_auto($_POST['Titulo']), "text"),
GetSQLValueString(strip_tags($_POST['Mensajes']), "text"),
GetSQLValueString($_POST['Mensajes'], "text"),
GetSQLValueString($_POST['Categoria'], "int"),
GetSQLValueString($_POST['Autor'], "int"),
GetSQLValueString($_POST['Fecha'], "text"));

mysql_select_db($database_conexion, $conexion);
$Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

$insertGoTo = "Foro.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
0
Puntos
Por RodrigoS hace 114 meses
Principiante
Respuesta #5
Por si acaso este es el form del mismo archivo

<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<table align="center">
<tr valign="baseline">
<td>Title<br>
<input type="text" name="Titulo" placeholder="Title here" maxlength="100" value="" required size="52"></td>
</tr>
<tr valign="baseline">
<td>Message<br>
<textarea name="Mensajes" required class="ckeditor" cols="56" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td>Categories<br>
<select name="Categoria">
<option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Images</option>
<option value="2" <?php if (!(strcmp(2, ""))) {echo "SELECTED";} ?>>Downloads</option>
<option value="3" <?php if (!(strcmp(3, ""))) {echo "SELECTED";} ?>>Tutorials</option>
<option value="4" <?php if (!(strcmp(4, ""))) {echo "SELECTED";} ?>>Videos</option>
</select></td>
</tr>
<tr valign="baseline">
<td align="right"><input type="submit" onClick="ckeditor();" value="Add post"></td>
</tr>
</table>
<input type="hidden" name="SEO" value="">
<input type="hidden" name="Keywords" value="">
<input type="hidden" name="Descripcion" value="">
<input type="hidden" name="Autor" value="<?php echo $_SESSION['MM_Id']; ?>">
<input type="hidden" name="Fecha" value="Posted on <?php echo date("d/m/Y"). " at " . date("H:i:s")?>">
<input type="hidden" name="MM_insert" value="form2">
</form>
0
Puntos
Por RodrigoS hace 114 meses
Principiante
Respuesta #6
Hola muchachones, quiero comentar que esto suele suceder en modo local, pero cuando lo subes a un servidor no se como, pero se arregla.

Me ha pasado varias veces, que si lo escribo en HTML se ve bien, pero si lo extraigo de una base de datos con PHP, no se ven los símbolos. Si cambio el meta charset, puede que se me arregle lo extraído pero ahora el HTML se ve mal, jajaja. Pero cuando lo subo al servidor se ve bien y creo que al final eso es lo importante, el resultado final que es en el servidor.
0
Puntos
Por Jose hace 113 meses
Experto Sitio web
Compartir en facebook
Compartir en twitter
Compartir
Para comentar Inicia sesión o Registrate