Foros del Web » Programando para Internet » PHP »

PHP OO Ayud4 con un script .

Estas en el tema de Ayud4 con un script . en el foro de PHP en Foros del Web. Buenas noches amigos ; de Foros del web ,vengo nuevamente a pedir su ayuda frente esto . Este es un registro que estado desarrollando y ...
  #1 (permalink)  
Antiguo 25/05/2013, 18:07
Avatar de nexus44  
Fecha de Ingreso: octubre-2012
Ubicación: Piura
Mensajes: 108
Antigüedad: 11 años, 5 meses
Puntos: 1
Ayud4 con un script .

Buenas noches amigos ; de Foros del web ,vengo nuevamente a pedir su ayuda frente esto .

Este es un registro que estado desarrollando y el siguiente problema o bueno lo que quisiera es que me ayuden ; al momento que doy clik en el boton registrar y hay campos vacios , me aparesca un script ; dando un mensaje "Faltan rellenar campos".

Código PHP:
Ver original
  1. <?php require_once('Connections/con_usuarios.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. // *** Redirect if username exists
  35. $MM_flag="MM_insert";
  36. if (isset($_POST[$MM_flag])) {
  37.   $MM_dupKeyRedirect="ya_existe.php";
  38.   $loginUsername = $_POST['nombre_user'];
  39.   $LoginRS__query = sprintf("SELECT nombre_user FROM usuarios WHERE nombre_user=%s", GetSQLValueString($loginUsername, "text"));
  40.   mysql_select_db($database_con_usuarios, $con_usuarios);
  41.   $LoginRS=mysql_query($LoginRS__query, $con_usuarios) or die(mysql_error());
  42.   $loginFoundUser = mysql_num_rows($LoginRS);
  43.  
  44.   //if there is a row in the database, the username was found - can not add the requested username
  45.   if($loginFoundUser){
  46.     $MM_qsChar = "?";
  47.     //append the username to the redirect page
  48.     if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
  49.     $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
  50.     header ("Location: $MM_dupKeyRedirect");
  51.     exit;
  52.   }
  53. }
  54.  
  55. $editFormAction = $_SERVER['PHP_SELF'];
  56. if (isset($_SERVER['QUERY_STRING'])) {
  57.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  58. }
  59.  
  60. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  61.   $insertSQL = sprintf("INSERT INTO usuarios (nombre_user, nombre, apellido, password, email, imagen) VALUES (%s, %s, %s, %s, %s, %s)",
  62.                        GetSQLValueString($_POST['nombre_user'], "text"),
  63.                        GetSQLValueString($_POST['nombre'], "text"),
  64.                        GetSQLValueString($_POST['apellido'], "text"),
  65.                        GetSQLValueString($_POST['password'], "text"),
  66.                        GetSQLValueString($_POST['email'], "text"),
  67.                        GetSQLValueString($_POST['imagen'], "text"));
  68.  
  69.   mysql_select_db($database_con_usuarios, $con_usuarios);
  70.   $Result1 = mysql_query($insertSQL, $con_usuarios) or die(mysql_error());
  71.  
  72.   $insertGoTo = "entrada.php";
  73.   if (isset($_SERVER['QUERY_STRING'])) {
  74.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  75.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  76.   }
  77.   header(sprintf("Location: %s", $insertGoTo));
  78. }
  79. ?>
  80.  
  81. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  82. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/base.dwt.php" codeOutsideHTMLIsLocked="false" -->
  83. <head>
  84. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  85. <!-- InstanceBeginEditable name="doctitle" -->
  86. <title>.:Registro de usuarios::.</title>
  87. <!-- InstanceEndEditable -->
  88. <style type="text/css">
  89. <!--
  90. body {
  91.     margin-top: 0px;
  92.     background-image: url(fondo.jpg);
  93.     background-repeat: repeat-x;
  94. }
  95. -->
  96. </style>
  97. <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  98. </head>
  99.  
  100. <body>
  101. <table width="80%" border="0" align="center">
  102.  
  103.   <tr>
  104.     <td align="center" bgcolor="#129ae8"><!-- InstanceBeginEditable name="contenido" -->
  105.  
  106.       <h2><img src="imagenes/rgus.jpg" width="500" height="100" /></h2>
  107.       <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  108.         <table align="center">
  109.           <tr valign="baseline">
  110.             <td nowrap="nowrap" align="right"><strong>Usuario:</strong></td>
  111.             <td><input type="text" name="nombre_user" value="" size="32" /></td>
  112.           </tr>
  113.           <tr valign="baseline">
  114.             <td nowrap="nowrap" align="right"><strong>Nombre:</strong></td>
  115.             <td><input type="text" name="nombre" value="" size="32" /></td>
  116.           </tr>
  117.           <tr valign="baseline">
  118.             <td nowrap="nowrap" align="right"><strong>Apellido:</strong></td>
  119.             <td><input type="text" name="apellido" value="" size="32" /></td>
  120.           </tr>
  121.           <tr valign="baseline">
  122.             <td nowrap="nowrap" align="right"><strong>Contraseña:</strong></td>
  123.             <td><input type="password" name="password" value="" size="32" /></td>
  124.           </tr>
  125.           <tr valign="baseline">
  126.             <td nowrap="nowrap" align="right"><strong>E-mail:</strong></td>
  127.             <td><input type="text" name="email" value="" size="32" /></td>
  128.           </tr>
  129.           <tr valign="baseline">
  130.             <td nowrap="nowrap" align="right"><strong>Imagen:</strong></td>
  131.             <td><input type="text" name="imagen" value="" size="32" /></td>
  132.           </tr>
  133.           <tr valign="baseline">
  134.             <td nowrap="nowrap" align="right">&nbsp;</td>
  135.             <td><input type="submit" value="Insertar usuario" /></td>
  136.           </tr>
  137.         </table>
  138.         <input type="hidden" name="MM_insert" value="form1" />
  139.       </form>
  140.      
  141.       <p>&nbsp;</p>
  142.     <!-- InstanceEndEditable --></td>
  143.   </tr>
  144. </table>
  145. </body>
  146. <!-- InstanceEnd --></html>
__________________

"Nuestra capacidad se aleja de la Humanidad"
  #2 (permalink)  
Antiguo 25/05/2013, 23:38
 
Fecha de Ingreso: febrero-2013
Mensajes: 163
Antigüedad: 11 años, 2 meses
Puntos: 1
Respuesta: Ayud4 con un script .

Con Javascript:

En el form pones este código onsubmit="return validar();" y en el head el javascript:

Código:
 function validar(){
	
	if(document.form1.nombre_user.value==''){
    alert('El campo nombre_user está vacío');
    document.form1.nombre_user.focus();
    return false;
    }
    }
luego haces lo mismo para cada campo


Con PHP
Código PHP:
if(empty($_POST['nombre_user'])) { // compruebas que el campo nombre_user no esté vacío
            
echo "El campo nombre_user está vacío. <a href='javascript:history.back();'>Reintentar</a>";
}else { 
//aquí el resto de tu código 
nuevamente haces una comprobación para cada campo
  #3 (permalink)  
Antiguo 27/05/2013, 14:22
Avatar de nexus44  
Fecha de Ingreso: octubre-2012
Ubicación: Piura
Mensajes: 108
Antigüedad: 11 años, 5 meses
Puntos: 1
Respuesta: Ayud4 con un script .

Muchas gracias por el aporte mathiasmontiel; especiificamente podrias colocarlo propiamente junto con mi codigo lo he colocado y sin embargo sigo teniendo un problema similar que no cumple mi requerimiento pedido.

GRACIAS.
__________________

"Nuestra capacidad se aleja de la Humanidad"

Etiquetas: html, mysql, registro, select, sql, 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 07:16.