Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

problema al conectar la base de datos.

Estas en el tema de problema al conectar la base de datos. en el foro de Mysql en Foros del Web. Buenas noches soy nueva en esto, estoy trabajando en un proyecto echo con la ayuda de dreamweaver, me funciona bien en el servidor local de ...
  #1 (permalink)  
Antiguo 14/11/2011, 20:54
 
Fecha de Ingreso: julio-2009
Ubicación: colombia
Mensajes: 7
Antigüedad: 14 años, 9 meses
Puntos: 0
problema al conectar la base de datos.

Buenas noches soy nueva en esto, estoy trabajando en un proyecto echo con la ayuda de dreamweaver, me funciona bien en el servidor local de xampp, pero cuando le hago las pruebas en el servidor de miarroba, me carga los formularios, pero cuando le doy enviar, ninguno me funciona, no me conecta la base de datos y me sale este error...

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/webcindario/p/e/petweb/registrar_usuario.php on line 79

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/webcindario/p/e/petweb/registrar_usuario.php on line 80

El codigo de la linea 79 y 80 es este..

mysql_select_db($database_registro_usuarios, $registro_usuarios);
$LoginRS=mysql_query($LoginRS__query, $registro_usuarios) or die(mysql_error());


y el codigo completo cabe aclarar que lo cree con la ayuda de dreamwaver, por el tiempo que dispongo... MUCHAS GRACIAS A TODOS LOS QUE ME PUEDAN AYUDAR...


<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexion_petweb = "mysql.webcindario.com";
$database_conexion_petweb = "petweb";
$username_conexion_petweb = "******";
$password_conexion_petweb = "******";
$conexion_petweb = mysql_pconnect($hostname_conexion_petweb, $username_conexion_petweb, $password_conexion_petweb) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

// *** Comprobar si nombre de usuario existe
$error = array();
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
// comprobar nombre
if (empty($_POST['nombre']) || empty($_POST['apellidos'])) {
$error['nombre'] = 'Por favor escribe tanto el nombre como los apellidos';
}
// configura un indicador que asume que la contraseña es correcta
$contbien = true;
// eliminar espacios en blanco
$_POST['contrase'] = trim($_POST['contrase']);
// si menos de 6 caracteres, creamos una alerta y configuramos indicador como false
if (strlen($_POST['contrase']) < 6) {
$error['contrase_tam'] = 'Tu contraseña debe tener al menos 6 caracteres';
$contbien = false;
}
// si no concuerda, crea una alerta y configura indicador a false
if ($_POST['contrase'] != trim($_POST['conf_cont'])) {
$error['contrase'] = 'Tu contraseña y la confirmacion no coiciden';
$contbien = false;
}
// si la contraseña es correcta, la encriptamos
if ($contbien) {
$_POST['contrase'] = sha1($_POST['contrase']);
}
// expresión regular para identificar caracteres ilegales en la dirección email
$comprobarEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
if (!preg_match($comprobarEmail, trim($_POST['email']))) {
$error['email'] = 'Por favor escribe una dirección email válida';
}
// comprobar nombre usuario
$_POST['nombreusuario'] = trim($_POST['nombreusuario']);
$loginUsername = $_POST['nombreusuario'];
if (strlen($loginUsername) < 6) {
$error['tama'] = 'Por favor selecciona un nombre de usuario que tenga al menos 6 caracteres';
}
$LoginRS__query = sprintf("SELECT nombreusuario FROM usuarios WHERE nombreusuario=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_registro_usuarios, $registro_usuarios);
$LoginRS=mysql_query($LoginRS__query, $registro_usuarios) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);

//Si el nombre de usuario ya se encuentra en la base de datos - no se puede añadir el nombre de usuario solicitado
if($loginFoundUser){
$error['nombreusuario'] = "$loginUsername ya está en uso. Por favor elige un nombre de usuario diferente.";

}
}

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

if (!$error) {
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO usuarios (nombre, apellidos, email, nombreusuario, contrase, admin_priv) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['apellidos'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['nombreusuario'], "text"),
GetSQLValueString($_POST['contrase'], "text"),
GetSQLValueString($_POST['admin_priv'], "text"));
echo "SE A GUARDADO EL NUEVO REGISTRO";

mysql_select_db($database_registro_usuarios, $registro_usuarios);
$Result1 = mysql_query($insertSQL, $registro_usuarios) or die(mysql_error());

}

// si el registro ha sido insertado, limpiar el array $_POST
$_POST = array();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registro Usuarios</title>
</head>

<body>
<h1>Registro Usuarios </h1>
<p>&nbsp;</p>
<?php
if ($error) {
echo '<ul>';
foreach ($error as $alerta) {
echo "<li class='warning'>$alerta</li>\n";
}
echo '</ul>';
// remove escape characters from POST array
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);

}
}
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre:</td>
<td><input value="<?php if (isset($_POST['nombre'])) {
echo htmlentities($_POST['nombre']);} ?>" name="nombre" type="text" id="nombre" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Apellidos:</td>
<td><input value="<?php if (isset($_POST['apellidos'])) {
echo htmlentities($_POST['apellidos']);} ?>" type="text" name="apellidos" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Email:</td>
<td><input value="<?php if (isset($_POST['email'])) {
echo htmlentities($_POST['email']);} ?>" type="text" name="email" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre Usuario:</td>
<td><input value="<?php if (isset($_POST['nombreusuario'])) {
echo htmlentities($_POST['nombreusuario']);} ?>" type="text" name="nombreusuario" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Contrase&ntilde;a:</td>
<td><input type="password" name="contrase" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Conf. Contrase&ntilde;a</td>
<td valign="baseline"><input name="conf_cont" type="password" id="conf_cont" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap">Admin_priv:</td>
<td valign="baseline"><table>
<tr>
<td><input <?php if ($_POST && !(strcmp($_POST['admin_priv'],"s"))) {echo "checked=\"checked\"";} ?> type="radio" name="admin_priv" value="s"/>
S&iacute;</td>
</tr>
<tr>
<td><input <?php if (($_POST &&!(strcmp($_POST['admin_priv'],"n")))||!$_POST) {echo "checked=\"checked\"";} ?> type="radio" name="admin_priv" value="n" />
No</td>
</tr>
</table></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Insertar registro" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>

Última edición por jenju302; 14/11/2011 a las 21:02
  #2 (permalink)  
Antiguo 14/11/2011, 22:27
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: problema al conectar la base de datos.

$registro_usuarios y $database_registro_usuarios que valor tiene no los encuentro??

mysql_select_db($database_registro_usuarios, $conexion_petweb);
$LoginRS=mysql_query($LoginRS__query, $conexion_petweb) or die(mysql_error());

o tambien podria ser asi , por que la conexion la haces en la misma pagina y no cierras la conexion

mysql_select_db($database_registro_usuarios);
$LoginRS=mysql_query($LoginRS__query) or die(mysql_error());

no se pruena haber esas 2 formas pero si especificas las 2 variables que te pregunte podriamos aclararlo mucho mas
  #3 (permalink)  
Antiguo 15/11/2011, 21:27
 
Fecha de Ingreso: julio-2009
Ubicación: colombia
Mensajes: 7
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: problema al conectar la base de datos.

Tengo una duda con myIsam, ya que en el localhost cree la base de datos con InnoDB, y me funcionan todos los campos dinamicos, pero en el servidor de de miaarroba, solo esta para crear la base de datos en myIsam y no me funcionando correctamente.... Espero toda la colaboracion que puedan dar ya que tengo que entregar este trabajo de la u el proximo mes...

por ejemplo este es el codigo de loguin.php, y este es el error que aun no identifico,,

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/webcindario/p/e/petweb/login.php on line 59

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/webcindario/p/e/petweb/login.php on line 64


<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexion_petweb = "mysql.webcindario.com";
$database_conexion_petweb = "petweb";
$username_conexion_petweb = "petweb";
$password_conexion_petweb = "jenifer302";
$conexion_petweb = mysql_pconnect($hostname_conexion_petweb, $username_conexion_petweb, $password_conexion_petweb) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
if (isset($_POST['contrase'])){$_POST['contrase'] =sha1($_POST['contrase']);}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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['nombreusuario'])) {
$loginUsername=$_POST['nombreusuario'];
$password=$_POST['contrase'];
$MM_fldUserAuthorization = "admin_priv"; //
$MM_redirectLoginSuccess = "correcto.php";
$MM_redirectLoginFailed = "fallo.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_registro_usuarios, $registro_usuarios);

$LoginRS__query=sprintf("SELECT nombreusuario, contrase, admin_priv FROM usuarios WHERE nombreusuario=%s AND contrase=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $registro_usuarios) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {

$loginStrGroup = mysql_result($LoginRS,0,'admin_priv');

//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 );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login</title>
</head>

<body>
<form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
<table width="268" border="0" cellspacing="5">
<tr>
<td>Nombre usuaurio</td>
<td><label>
<input type="text" name="nombreusuario" id="nombreusuario" />
</label></td>
</tr>
<tr>
<td>Contrase&ntilde;a</td>
<td><label>
<input type="password" name="contrase" id="contrase" />
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<input type="submit" name="hacerLogin" id="hacerLogin" value="Autentificar" />
</label></td>
</tr>
</table>
</form>
</body>
</html>

Última edición por jenju302; 15/11/2011 a las 21:36
  #4 (permalink)  
Antiguo 20/11/2011, 12:45
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: problema al conectar la base de datos.

Cita:
Iniciado por webankenovi Ver Mensaje
$registro_usuarios y $database_registro_usuarios que valor tiene no los encuentro??

mysql_select_db($database_registro_usuarios, $conexion_petweb);
$LoginRS=mysql_query($LoginRS__query, $conexion_petweb) or die(mysql_error());

o tambien podria ser asi , por que la conexion la haces en la misma pagina y no cierras la conexion

mysql_select_db($database_registro_usuarios);
$LoginRS=mysql_query(consulta) or die(mysql_error());

no se pruena haber esas 2 formas pero si especificas las 2 variables que te pregunte podriamos aclararlo mucho mas

Etiquetas: php, query, select, sql
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 11:38.