Hola de nuevo, estoy teniendo problemas con el archvio funciones.php pasando a MYSQLI, me sale el error Undefined variable: database_conexion y varios mas de este tipo de la variable $datosWeb no se porque bota el error, aparentemente no se logra conectar, pero cual es el error? ¡Ayuda!
conexion.php
Editado
conexion.php
<?php
//SESSIONES
if (!isset($_SESSION)) {
session_start();
}
$hostname_conexion = "localhost";
$database_conexion = "dacf";
$username_conexion = "root";
$password_conexion = "";
$conexion = mysqli_connect($hostname_db, $username_db, $password_db);
include('inc/funciones.php')
?>funciones.php<?php
//FORMATEO BASE DE DATOS
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
//Iniciamos la variable $conexion
global $conexion;
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
//Agregamos $conexion en las funciones mysqli_real_escape_string y mysqli_escape_string
$theValue = $conexion("mysqli_real_escape_string") ? mysqli_real_escape_string($conexion,$theValue) : $conexion($conexion,$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;
}
//FORMATO DE CARACTERES
header('Content-Type: text/html; charset=iso-8859-1');
//CONSULTA BASE DATOS
mysqli_select_db($conexion, $database_conexion);
$query_DatosWeb = "SELECT * FROM d_datos";
$DatosWeb = mysqli_query($conexion, $query_DatosWeb) or die(mysqli_error());
$row_DatosWeb = mysqli_fetch_assoc($DatosWeb);
$totalRows_DatosWeb = mysqli_num_rows($DatosWeb);
mysqli_free_result($DatosWeb);
function nombre($iduser){
global $database_conexion, $conexion;
mysqli_select_db($conexion, $database_conexion);
$query_DatosFuncion = sprintf("SELECT user FROM d_users WHERE id=%s",
GetSQLValueString($iduser, "int"));
$DatosFuncion = mysqli_query($conexion, $query_DatosFuncion) or die(mysqli_error());
$row_DatosFuncion = mysqli_fetch_assoc($DatosFuncion);
$totalRows_DatosFuncion = mysqli_num_rows($DatosFuncion);
return $row_DatosFuncion['user'];
mysqli_free_result($DatosFuncion);
}
function recordarsesion($user,$pass){
setcookie("usercookie", $user, time() + (365 * 24 * 60 * 60),"/");
setcookie("passcookie", $pass, time() + (365 * 24 * 60 * 60),"/");
}
if (isset($_COOKIE['usercookie']) && isset($_COOKIE['passcookie']) && !isset($_SESSION['iduser'])) {
mysqli_select_db($conexion, $database_conexion);
$query_DatosLogin = sprintf("SELECT * FROM d_users WHERE user=%s AND password=%s",
GetSQLValueString($_COOKIE['usercookie'], "text"),
GetSQLValueString($_COOKIE['passcookie'], "text"));
$DatosLogin = mysqli_query($conexion, $query_DatosLogin) or die(mysqli_error());
$row_DatosLogin = mysqli_fetch_assoc($DatosLogin);
$totalRows_DatosLogin = mysqli_num_rows($DatosLogin);
if ($totalRows_DatosLogin==1){
$_SESSION['iduser']=$row_DatosLogin['id'];
$_SESSION['nombreuser']=$row_DatosLogin['user'];
}
mysqli_free_result($DatosLogin);
}
?>Editado
0
Puntos
Puntos
1824
Visitas
Visitas
11
Resp
Resp
Por andresc9410 hace 9 años
Novice
Respuesta #1
hola tienes que usar la función getsqlvaluestring para mysqli, aquí la tienes https://phpres.net/php-poo/formatear-cadena-con-funcion-getsqlvaluestring-en-mysqli
0
Puntos
Puntos
Por alber hace 9 años
Admin
Respuesta #2
Ya la tenía.. sigue con el error
0
Puntos
Puntos
Por andresc9410 hace 9 años
Novice
Respuesta #3
claro el error $databas_conexion es por que en el fichero conexion no la tienes ademas no tienes bien los nombres de las variables, mira haz que conexion.php quede exactamente así:
<?php
//SESSIONES
if (!isset($_SESSION)) {
session_start();
}
$hostname_conexion = "localhost";
$database_conexion = "dacf";
$username_conexion = "root";
$password_conexion = "";
$conexion = mysqli_connect($hostname_conexion, $username_conexion, $password_conexion);
mysqli_select_db($conexion,$database_conexion) or die ("Ninguna DB seleccionada");
include('inc/funciones.php')
?>con eso ya lo tienes saludos0
Puntos
Puntos
Por alber hace 9 años
Admin
Respuesta #4
Gracias por responder alber, esto de mysql es complicado, me da error la variable "dato" NOTICE: UNDEFINED VARIABLE dato, de la consulta a base de datos "DatosWeb", ´pongo el código para que porfavor me ayudes.
funciones.php
funciones.php
<?php //Formateo Base de datos
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
global $conexion;
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conexion, $theValue) : mysqli_escape_string($conexion, $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;
}
}
//FORMATO DE CARACTERES
header('Content-Type: text/html; charset=iso-8859-1');
//CONSULTA BASE DATOS
mysqli_select_db($conexion, $database_conexion);
$query_DatosWeb = "SELECT * FROM d_datos";
$DatosWeb = mysqli_query($conexion, $query_DatosWeb) or die(mysqli_error());
$row_DatosWeb = mysqli_fetch_assoc($DatosWeb);
$totalRows_DatosWeb = mysqli_num_rows($DatosWeb);
mysqli_free_result($DatosWeb);
function nombre($iduser){
global $database_conexion, $conexion;
mysqli_select_db($conexion, $database_conexion);
$query_DatosFuncion = sprintf("SELECT user FROM d_users WHERE id=%s",
GetSQLValueString($iduser, "int"));
$DatosFuncion = mysqli_query($conexion, $query_DatosFuncion) or die(mysqli_error());
$row_DatosFuncion = mysqli_fetch_assoc($DatosFuncion);
$totalRows_DatosFuncion = mysqli_num_rows($DatosFuncion);
return $row_DatosFuncion['user'];
mysqli_free_result($DatosFuncion);
}
function recordarsesion($user,$pass){
setcookie("usercookie", $user, time() + (365 * 24 * 60 * 60),"/");
setcookie("passcookie", $pass, time() + (365 * 24 * 60 * 60),"/");
}
if (isset($_COOKIE['usercookie']) && isset($_COOKIE['passcookie']) && !isset($_SESSION['iduser'])) {
mysqli_select_db($conexion, $database_conexion);
$query_DatosLogin = sprintf("SELECT * FROM d_users WHERE user=%s AND password=%s",
GetSQLValueString($_COOKIE['usercookie'], "text"),
GetSQLValueString($_COOKIE['passcookie'], "text"));
$DatosLogin = mysqli_query($conexion, $query_DatosLogin) or die(mysqli_error());
$row_DatosLogin = mysqli_fetch_assoc($DatosLogin);
$totalRows_DatosLogin = mysqli_num_rows($DatosLogin);
if ($totalRows_DatosLogin==1){
$_SESSION['iduser']=$row_DatosLogin['id'];
$_SESSION['nombreuser']=$row_DatosLogin['user'];
}
mysqli_free_result($DatosLogin);
}
?>0
Puntos
Puntos
Por andresc9410 hace 9 años
Novice
Respuesta #5
Olvidalo ya lo resolví, fue un descuido mio, gracias por responder.
0
Puntos
Puntos
Por andresc9410 hace 9 años
Novice
Respuesta #6
la variable $dato no existe en tu código por eso te dice que no esta definida, te falta hacer esto:
//CONSULTA BASE DATOS
mysqli_select_db($conexion, $database_conexion);
$query_DatosWeb = "SELECT * FROM d_datos";
$DatosWeb = mysqli_query($conexion, $query_DatosWeb) or die(mysqli_error());
$row_DatosWeb = mysqli_fetch_assoc($DatosWeb);
$totalRows_DatosWeb = mysqli_num_rows($DatosWeb);
$dato=array($row_DatosWeb['url']); // Agregar los demas valores de $dato
mysqli_free_result($DatosWeb);0
Puntos
Puntos
Por alber hace 9 años
Admin
Respuesta #7
Sigo con mas problemas, y creo que vendran más, espero me tengan pasciencia y me ayuden.
Al abrir el link para id post me sale error, el error dice que es de está linea:
Al abrir el link para id post me sale error, el error dice que es de está linea:
$query_DatosImg = "SELECT * FROM d_imgs WHERE idpost=%s",$row_DatosVer['id'],"int");aqui pego el código
<?php require_once("conexion.php");
if (!isset($_SESSION['iduser'])){
header('Location:'.$dato['0']);
}
$idpost= $_GET['id'];
//CONSULTA BASE DATOS
mysqli_select_db($conexion, $database_conexion);
$query_DatosVer = "SELECT * FROM d_post WHERE id='$idpost'";
$DatosVer = mysqli_query($conexion, $query_DatosVer) or die(mysqli_error());
$row_DatosVer = mysqli_fetch_assoc($DatosVer);
$totalRows_DatosVer = mysqli_num_rows($DatosVer);
mysqli_select_db($conexion, $database_conexion);
$query_DatosImg = "SELECT * FROM d_imgs WHERE idpost=%s",$row_DatosVer['id'],"int");
$DatosImg = mysqli_query($conexion, $query_DatosImg) or die(mysqli_error());
$row_DatosImg = mysqli_fetch_assoc($DatosImg);
$totalRows_DatosImg = mysqli_num_rows($DatosImg);
?>
<!-- CÓDIGO HTML -->
<?php mysqli_free_result($DatosVer);?>
<?php mysqli_free_result($DatosImg);?>0
Puntos
Puntos
Por andresc9410 hace 9 años
Novice
Respuesta #8
no puedes usar:
$query_DatosImg = "SELECT * FROM d_imgs WHERE idpost=%s",$row_DatosVer['id'],"int");pero puedes hacer esto:
$iddelpost=$row_DatosVer['id']; $query_DatosImg = "SELECT * FROM d_imgs WHERE idpost=%s",$iddelpost,"int";
0
Puntos
Puntos
Por alber hace 9 años
Admin
Respuesta #9
refresca la pagina que eh editado la respuesta
0
Puntos
Puntos
Por alber hace 9 años
Admin
Respuesta #10
me sigue dando el mismo error Parse error: syntax error, unexpected ',' in C:\AppServ\www\dacf\ver_post.php on line 18
0
Puntos
Puntos
Por andresc9410 hace 9 años
Novice
Respuesta #11
logre solucionar, ahora se muestra la página de ver_post pero en la minuatura se muestra una imagen de fotos.php "las que uno sube" y en la parte donde se debe mostrar las fotos (fotos.php) aparece este error Warning: mysqli_free_result() [function.mysqli-free-result]: Couldn't fetch mysqli_result in C:\AppServ\www\dacfmovies\ver_peli.php on line 166 y sigue sin mostrarse el titulo y el contenido en el html porque pongo el echo en el titulo y si lo muestra, no entiendo cual es el error, ya e mirado todo, e revisado los vídeos y nada :/
0
Puntos
Puntos
Por andresc9410 hace 9 años
Novice