Foros del Web » Programando para Internet » PHP »

ERROR -> Warning: mysql_select_db(): supplied argument...

Estas en el tema de ERROR -> Warning: mysql_select_db(): supplied argument... en el foro de PHP en Foros del Web. Despues de solucionar de una santa vez unos problemas con el hosting me ha surgido otro problema que no se de que va... es algo ...
  #1 (permalink)  
Antiguo 04/06/2012, 17:40
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
ERROR -> Warning: mysql_select_db(): supplied argument...

Despues de solucionar de una santa vez unos problemas con el hosting me ha surgido otro problema que no se de que va... es algo relacionado con el link que no es correcto pero no entiendo mucho de PHP y espero que alguien me pueda echar una mano!!

Gracias de antemano!

Dejo el codigo para ver si veis algo extraño!

Código PHP:
<?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['username'])) {
  
$loginUsername=$_POST['username'];
  
$password=$_POST['password'];
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "autorizacion.php";
  
$MM_redirectLoginFailed "login.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_MiConexion$MiConexion);
  
  
$LoginRS__query=sprintf("SELECT usuario, contrasena FROM usuarios WHERE usuario=%s AND contrasena=%s",
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$MiConexion) or die(mysql_error());
  
$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;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>



<?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;
}
}
?>
Los errores que me da son :

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/tgsforma/public_html/cursos/login.php on line 19

Fatal error: Call to undefined function getsqlvaluestring() in /home/tgsforma/public_html/cursos/login.php on line 22
  #2 (permalink)  
Antiguo 04/06/2012, 17:50
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Pues en la linea que indica el error:
Código PHP:
mysql_select_db($database_MiConexion$MiConexion); 
Ahí le pasas dos variables, de las cuales ninguna has definido en todo tu script.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 04/06/2012, 18:04
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Cita:
Iniciado por pateketrueke Ver Mensaje
Pues en la linea que indica el error:
Código PHP:
mysql_select_db($database_MiConexion$MiConexion); 
Ahí le pasas dos variables, de las cuales ninguna has definido en todo tu script.
Lo primero muchas gracias por contestar!!

Lo segundo soy novato en este tema.

Esas son las variables que se encuentran en el archivo de Conexion que contiene:

Código PHP:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_MiConexion "mysql01"// EN VEZ DE PONER 'localhost'
$database_MiConexion "nombre_ddbb";
$username_MiConexion "nombre_user";
$password_MiConexion "pass";
$conexion mysql_pconnect($hostname_MiConexion$username_MiConexion$password_MiConexion) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
  #4 (permalink)  
Antiguo 04/06/2012, 18:07
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Entiendo, pero ¿donde incluyes dicho archivo?

Los archivos no se incluyen solos, de modo que debes incluir tu archivo de configuración antes de hacer uso de las variables que ahí contiene.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 04/06/2012, 18:08
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Cita:
Iniciado por pateketrueke Ver Mensaje
Entiendo, pero ¿donde incluyes dicho archivo?

Los archivos no se incluyen solos, de modo que debes incluir tu archivo de configuración antes de hacer uso de las variables que ahí contiene.
Me falto por poner en el primer post que termino haciendo la conexion con:

<?php require_once('Connections/MiConexion.php'); ?>
  #6 (permalink)  
Antiguo 04/06/2012, 18:10
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

¿Terminas haciendo la conexión?

Como te digo, eso debes hacerlo con orden, no puedes hacer uso de variables que incluyes después determinado contexto.

Además te sugiero también revisar el log de errores, pues cabe la posibilidad de que algo ocurra pero como no te das cuenta pues terminas pensando que el problema es de tu código actual.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #7 (permalink)  
Antiguo 04/06/2012, 18:13
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Cita:
Iniciado por pateketrueke Ver Mensaje
¿Terminas haciendo la conexión?

Como te digo, eso debes hacerlo con orden, no puedes hacer uso de variables que incluyes después determinado contexto.

Además te sugiero también revisar el log de errores, pues cabe la posibilidad de que algo ocurra pero como no te das cuenta pues terminas pensando que el problema es de tu código actual.
no entiendo muy bien tu respuesta, como te digo, soy novato en este tema, tenia entendido que lo primero de todo es colocar las sesiones!! con lo cual si eso es lo primero la conexión donde la hago??

y que es eso del log de errores???


Muchísimas gracias!!
  #8 (permalink)  
Antiguo 04/06/2012, 18:16
Avatar de patriciomase  
Fecha de Ingreso: abril-2012
Ubicación: Mar del Plata
Mensajes: 323
Antigüedad: 12 años
Puntos: 34
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

el include va al principio, a partir del include vas a tener disponibles las variables de conexion, antes no, no existen!!
  #9 (permalink)  
Antiguo 04/06/2012, 18:20
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Código PHP:
<?php require_once('Connections/MiConexion.php'); ?>

<?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['username'])) {
  
$loginUsername=$_POST['username'];
  
$password=$_POST['password'];
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "autorizacion.php";
  
$MM_redirectLoginFailed "login.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_MiConexion$MiConexion);
  
  
$LoginRS__query=sprintf("SELECT usuario, contrasena FROM usuarios WHERE usuario=%s AND contrasena=%s",
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$MiConexion) or die(mysql_error());
  
$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;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>

<?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;
}
}
?>
Poniendolo asi este es el error de sesion que me aparece, directamente en el login, los otros dos errores me salian al hacer el login, no ahora que ya me sale antes de introducir user y pass

Código PHP:
Warningsession_start() [function.session-start]: Cannot send session cache limiter headers already sent (output started at /home/tgsforma/public_html/cursos/Connections/MiConexion.php:12in /home/tgsforma/public_html/cursos/login.php on line 6 
  #10 (permalink)  
Antiguo 05/06/2012, 05:24
Avatar de oNefl0w189  
Fecha de Ingreso: abril-2010
Ubicación: Valladolid
Mensajes: 117
Antigüedad: 14 años
Puntos: 4
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

prueba así:

Código PHP:
Ver original
  1. <?php
  2. include('Connections/MiConexion.php');
  3. // *** Validate request to login to this site.
  4. if (!isset($_SESSION)) {
  5. }
  6.  
  7. $loginFormAction = $_SERVER['PHP_SELF'];
  8. if (isset($_GET['accesscheck'])) {
  9.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  10. }
  11.  
  12. if (isset($_POST['username'])) {
  13.   $loginUsername=$_POST['username'];
  14.   $password=$_POST['password'];
  15.   $MM_fldUserAuthorization = "";
  16.   $MM_redirectLoginSuccess = "autorizacion.php";
  17.   $MM_redirectLoginFailed = "login.php";
  18.   $MM_redirecttoReferrer = false;
  19.   mysql_select_db($database_MiConexion, $MiConexion);
  20.    
  21.   $LoginRS__query=sprintf("SELECT usuario, contrasena FROM usuarios WHERE usuario=%s AND contrasena=%s",
  22.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));  
  23.    
  24.   $LoginRS = mysql_query($LoginRS__query, $MiConexion) or die(mysql_error());
  25.   $loginFoundUser = mysql_num_rows($LoginRS);
  26.   if ($loginFoundUser) {
  27.      $loginStrGroup = "";
  28.      
  29.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  30.     //declare two session variables and assign them
  31.     $_SESSION['MM_Username'] = $loginUsername;
  32.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  33.  
  34.     if (isset($_SESSION['PrevUrl']) && false) {
  35.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  36.     }
  37.     header("Location: " . $MM_redirectLoginSuccess );
  38.   }
  39.   else {
  40.     header("Location: ". $MM_redirectLoginFailed );
  41.   }
  42. }
  43. ?>
  44.  
  45. <?php
  46. if (!function_exists("GetSQLValueString")) {
  47. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
  48. {
  49.   if (PHP_VERSION < 6) {
  50.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  51.   }
  52.  
  53.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  54.  
  55.   switch ($theType) {
  56.     case "text":
  57.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  58.       break;    
  59.     case "long":
  60.     case "int":
  61.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  62.       break;
  63.     case "double":
  64.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  65.       break;
  66.     case "date":
  67.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  68.       break;
  69.     case "defined":
  70.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  71.       break;
  72.   }
  73.   return $theValue;
  74. }
  75. }
  76. ?>


Si no te funciona, prueba poniendo la linea

include('Connections/MiConexion.php');

en esta posicion:

session_start();
}
include('Connections/MiConexion.php');
__________________
Nunca dijeron que la vida sería fácil, sólo prometieron que valdría la pena vivirla.

Dar las gracias y añadir Karma, no cuesta nada, ¿Que menos si te ayudan? :)
  #11 (permalink)  
Antiguo 05/06/2012, 06:25
Avatar de oscartt67  
Fecha de Ingreso: abril-2012
Ubicación: fonollosa
Mensajes: 481
Antigüedad: 12 años
Puntos: 97
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

como dice oNefl0w189 este es el orden:
Código PHP:
session_start();
include(
'Connections/MiConexion.php'); 
saludos.
  #12 (permalink)  
Antiguo 12/06/2012, 07:03
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Estos son los errores que me dan ahora...

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/tgsforma/public_html/cursos/login.php on line 21

Fatal error: Call to undefined function getsqlvaluestring() in /home/tgsforma/public_html/cursos/login.php on line 24


y he puesto el codigo tal que así:

Código PHP:
<?php 

// *** Validate request to login to this site. 
if (!isset($_SESSION)) { 
  
session_start();



  include(
'Connections/MiConexion.php'); 
 
$loginFormAction $_SERVER['PHP_SELF']; 
if (isset(
$_GET['accesscheck'])) { 
  
$_SESSION['PrevUrl'] = $_GET['accesscheck']; 

 
if (isset(
$_POST['username'])) { 
  
$loginUsername=$_POST['username']; 
  
$password=$_POST['password']; 
  
$MM_fldUserAuthorization ""
  
$MM_redirectLoginSuccess "autorizacion.php"
  
$MM_redirectLoginFailed "login.php"
  
$MM_redirecttoReferrer false
  
mysql_select_db($database_MiConexion$MiConexion); 
   
  
$LoginRS__query=sprintf("SELECT usuario, contrasena FROM usuarios WHERE usuario=%s AND contrasena=%s"
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text"));  
    
  
$LoginRS mysql_query($LoginRS__query$MiConexion) or die(mysql_error()); 
  
$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;           
 
    if (isset(
$_SESSION['PrevUrl']) && false) { 
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];     
    } 
    
header("Location: " $MM_redirectLoginSuccess ); 
  } 
  else { 
    
header("Location: "$MM_redirectLoginFailed ); 
  } 

?> 
 
<?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


?>
El incllude lo he probado a colocar justo detras del session y tambien detras de la } pero nada...


Muchas gracias por contestar!!

a ver si me podeis seguir ayudando!!
  #13 (permalink)  
Antiguo 12/06/2012, 07:24
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

En la linea del primer error, ¿por qué estás usando $MiConexion si está claro desde tu código anterior la variable correcta es $conexion?

El segundo error es más sencillo, ¿ya te has dado cuenta que declaras la función GetSQLValueString() al final del código y no al principio?

Intenta declarar la función antes de usarla, no después.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #14 (permalink)  
Antiguo 12/06/2012, 14:02
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Cita:
Iniciado por pateketrueke Ver Mensaje
En la linea del primer error, ¿por qué estás usando $MiConexion si está claro desde tu código anterior la variable correcta es $conexion?

El segundo error es más sencillo, ¿ya te has dado cuenta que declaras la función GetSQLValueString() al final del código y no al principio?

Intenta declarar la función antes de usarla, no después.

Ok, Muchisimas Gracias, he solucionado el primero llamando a todo MiConexion para que no haya lugar a duda..

Sigo sin solucionar el segundo...
  #15 (permalink)  
Antiguo 12/06/2012, 14:11
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Cita:
Iniciado por pateketrueke Ver Mensaje
Intenta declarar la función antes de usarla, no después.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #16 (permalink)  
Antiguo 12/06/2012, 14:16
 
Fecha de Ingreso: abril-2012
Mensajes: 22
Antigüedad: 12 años
Puntos: 0
Respuesta: ERROR -> Warning: mysql_select_db(): supplied argument...

Solucionado el problema, es que entiendo el error de que estoy llamando a una funcion aun no definida, pero no sabia donde colocarla exactamente, ya que en PHP el orden es fundamental !!

Muchísimas gracias por todo!! Un abrazo

Etiquetas: html, mysql, sql, warning, variables, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:34.