hola chicos, pues eso tengo hecho un par de formularios de registros , pero tengo un problema , los son son casi igueles, pero en uno me sale esto
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '±a, avatar, nombre) VALUES (5, 'carlitos', 'saratoga', 'nada', 'manolito')' at line 1 , este es el codigo
Código PHP:
Ver original<?php require_once('Connections/prueba.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
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"] == "form1")) { $insertSQL = sprintf("INSERT INTO usuarios (id_usuario, usuario, contraseña, avatar, nombre) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['id_usuario'], "int"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['contraseña'], "text"),
GetSQLValueString($_POST['avatar'], "text"),
GetSQLValueString($_POST['nombre'], "text"));
$insertGoTo = "prueba.php";
if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ?
"&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING'];
}
}
$query_priemera_prueba = "SELECT * FROM usuarios";
?>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="354" align="center" bgcolor="#CC33CC">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Id_usuario:</td>
<td><input type="text" name="id_usuario" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Usuario:</td>
<td><input type="text" name="usuario" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td height="25" align="right" nowrap="nowrap">Clave:</td>
<td><input type="text" name="contraseña" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Avatar:</td>
<td><input type="text" name="avatar" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre:</td>
<td><input type="text" name="nombre" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insertar registro" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
?>
pero en este no me da error
Código PHP:
Ver original<?php require_once('Connections/prueba.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
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"] == "form1")) { $insertSQL = sprintf("INSERT INTO usuarios (id_usuario, usuario, clave, avatar, nombre) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['id_usuario'], "int"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['clave'], "text"),
GetSQLValueString($_POST['avatar'], "text"),
GetSQLValueString($_POST['nombre'], "text"));
$insertGoTo = "prueba.php";
if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ?
"&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING'];
}
}
$query_priemera_prueba = "SELECT * FROM usuarios";
?>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="354" align="center" bgcolor="#CC33CC">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Id_usuario:</td>
<td><input type="text" name="id_usuario" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Usuario:</td>
<td><input type="text" name="usuario" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td height="25" align="right" nowrap="nowrap">Clave:</td>
<td><input type="text" name="clave" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Avatar:</td>
<td><input type="text" name="avatar" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre:</td>
<td><input type="text" name="nombre" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insertar registro" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
?>
quizas el error sea lo de la contraseña, con eso de q lleva la ñ , la base de datos tiene cotejamiento ascii_general_ci , aunque tambien probe htf8 y me da el mismo error