Mi phpMyAdmin es 2.10.3, Versión del cliente: 5.0.51a, Versión del servidor: 5.0.51b-community-nt-log
Versión del protocolo: 10.
El error es el siguiente:
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 '' at line 1
Mi código en la conexión es éste:
Código PHP :
<?php if (!isset($_SESSION)) {
@session_start();
}?>
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_sitio1 = "localhost";
$database_sitio1 = "sitio1";
$username_sitio1 = "root";
$password_sitio1 = "xxxxx";
$sitio1 = mysql_pconnect($hostname_sitio1, $username_sitio1, $password_sitio1) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
include("includes/funciones.php");
?>El código del archivo que incluí en la BD, es:
Código PHP :
<?php if ((isset($_SESSION['MM_Username'])) && ($_SESSION['MM_Username'] != "")){
echo "Hola ". ObtenerNombreUsuario($_SESSION['MM_IdUsuario']);
}
else
{?>
<a href="alta_usuario.php">REGISTRARSE</a>
| <a href="acceso.php">INGRESAR</a>
<?php }?>La función, es:
Código PHP :
<?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;
}
}
function ObtenerNombreUsuario($identificador)
{
global $database_sitio1, $sitio1;
mysql_select_db($database_sitio1, $sitio1);
$query_ConsultaFuncion = sprintf("SELECT tblusuario.strNombre FROM tblusuario WHERE tblusuario.idUsuario = %s", $identificador);
$ConsultaFuncion = mysql_query($query_ConsultaFuncion, $sitio1) or die(mysql_error());
$row_ConsultaFuncion = mysql_fetch_assoc($ConsultaFuncion);
$totalRows_ConsultaFuncion = mysql_num_rows($ConsultaFuncion);
echo $row_ConsultaFuncion['strNombre'];
mysql_free_result($ConsultaFuncion);
}?>y el código de la sección: "acceso.php" es:
Código PHP :
<?php require_once('Connections/sitio1.php'); ?>
<?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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
@session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['strEmail'])) {
$loginUsername=$_POST['strEmail'];
$password=$_POST['strPassword'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "acceso_ok.php";
$MM_redirectLoginFailed = "acceso_error.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_sitio1, $sitio1);
$LoginRS__query=sprintf("SELECT idUsuario, strEmail, strPassword FROM tblusuario WHERE strEmail=%s AND strPassword=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $ventasonline) or die(mysql_error());
$row_LoginRS = mysql_fetch_assoc($LoginRS);
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$_SESSION['MM_IdUsuario'] = $row_LoginRS["idUsuario"];
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>¡DESDE YA, INFINITAS GRACIAS Y UN SALUDO! Espero pueda ir progresando en ésto. En mi ciudad, ni en las de alrededor hay cursos ni una carrera para programación web.
