Foros del Web » Programando para Internet » PHP »

No me inserta el contenido en la BD

Estas en el tema de No me inserta el contenido en la BD en el foro de PHP en Foros del Web. Hola a todos. Quería saber por qué no me inserta el contenido (me refiero al contenido que el usuario escribe en el textarea) en la ...
  #1 (permalink)  
Antiguo 07/10/2014, 04:10
Musiker
Invitado
 
Mensajes: n/a
Puntos:
No me inserta el contenido en la BD

Hola a todos.

Quería saber por qué no me inserta el contenido (me refiero al contenido que el usuario escribe en el textarea) en la base de datos, cuando el usuario se loguea. ¿Alguien me ayuda a ver dónde está el error? Gracias por adelantado. Os dejo el código de 2 archivos (index y blog). Faltaría el del registro, pero ya no me cabe por número de caracteres.

index.php

Código PHP:
<?php require_once('Connections/prueba.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['textfield'])) {
  
$loginUsername=$_POST['textfield'];
  
$password=$_POST['textfield2'];
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "blog.php";
  
$MM_redirectLoginFailed "index.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_prueba$prueba);
  
  
$LoginRS__query=sprintf("SELECT nombre, pass FROM nueva WHERE nombre=%s AND pass=%s",
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$prueba) 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 );
  }
}
?>
Código HTML:
Ver original
  1.  
  2. <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  3.   <p>
  4.     <label for="textfield">usuario</label>
  5.     <input type="text" name="textfield" id="textfield" />
  6.   </p>
  7.   <p>
  8.     <label for="textfield2">pass</label>
  9.     <input type="password" name="textfield2" id="textfield2" />
  10.   </p>
  11.   <p>
  12.     <input type="submit" name="button" id="button" value="Acceder" />
  13.   </p>
  14. </form>
  15. <p><a href="registrarse.php">Registrarse</a></p>
  16. </body>
  17. </html>

blog.php

Código PHP:
<?php require_once('Connections/prueba.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  
session_start();
}

// ** Logout the current user. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  
//to fully log out a visitor we need to clear the session varialbles
  
$_SESSION['MM_Username'] = NULL;
  
$_SESSION['MM_UserGroup'] = NULL;
  
$_SESSION['PrevUrl'] = NULL;
  unset(
$_SESSION['MM_Username']);
  unset(
$_SESSION['MM_UserGroup']);
  unset(
$_SESSION['PrevUrl']);
    
  
$logoutGoTo "index.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "";
$MM_donotCheckaccess "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
  
// For security, start by assuming the visitor is NOT authorized. 
  
$isValid False

  
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  
if (!empty($UserName)) { 
    
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    
$arrUsers Explode(","$strUsers); 
    
$arrGroups Explode(","$strGroups); 
    if (
in_array($UserName$arrUsers)) { 
      
$isValid true
    } 
    
// Or, you may restrict access to only certain users based on their username. 
    
if (in_array($UserGroup$arrGroups)) { 
      
$isValid true
    } 
    if ((
$strUsers == "") && true) { 
      
$isValid true
    } 
  } 
  return 
$isValid
}

$MM_restrictGoTo "index.php";
if (!((isset(
$_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  
$MM_qsChar "?";
  
$MM_referrer $_SERVER['PHP_SELF'];
  if (
strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
  if (isset(
$_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0
  
$MM_referrer .= "?" $_SERVER['QUERY_STRING'];
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<?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;
}
}

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO nueva (nombre, pass, contenido) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['pass'], "text"),
                       
GetSQLValueString($_POST['contenido'], "text"));

  
mysql_select_db($database_prueba$prueba);
  
$Result1 mysql_query($insertSQL$prueba) or die(mysql_error());

  
$insertGoTo "blog.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

$colname_miusuario "-1";
if (isset(
$_GET['MM_Username'])) {
  
$colname_miusuario $_GET['MM_Username'];
}
mysql_select_db($database_prueba$prueba);
$query_miusuario sprintf("SELECT * FROM nueva WHERE nombre = %s"GetSQLValueString($colname_miusuario"text"));
$miusuario mysql_query($query_miusuario$prueba) or die(mysql_error());
$row_miusuario mysql_fetch_assoc($miusuario);
$totalRows_miusuario mysql_num_rows($miusuario);

$colname_Recordset1 "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_Recordset1 $_SESSION['MM_Username'];
}
mysql_select_db($database_prueba$prueba);
$query_Recordset1 sprintf("SELECT contenido FROM nueva WHERE contenido = %s"GetSQLValueString($colname_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$prueba) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
Código HTML:
Ver original
  1. <p>Hola <?php echo $_SESSION['MM_Username']?></p>
  2. <p><a href="<?php echo $logoutAction ?>">Cerrar sesión</a></p>
  3. <p>&nbsp;</p>
  4. <p>&nbsp;</p>
  5. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  6.   <table align="center">
  7.     <tr valign="baseline">
  8.       <td nowrap="nowrap" align="right" valign="top">Contenido:</td>
  9.       <td><textarea name="contenido" cols="50" rows="5"></textarea></td>
  10.     </tr>
  11.     <tr valign="baseline">
  12.       <td nowrap="nowrap" align="right">&nbsp;</td>
  13.       <td><input type="submit" value="Publicar" /></td>
  14.     </tr>
  15.   </table>
  16.   <input type="hidden" name="nombre" value="<?php echo $row_miusuario['nombre']; ?>" />
  17.   <input type="hidden" name="pass" value="" />
  18.   <input type="hidden" name="MM_insert" value="<?php echo $row_miusuario['contenido']; ?>" />
  19. </form>
  20. </body>
  21. </html>
  22. <?php
  23. mysql_free_result($miusuario);
  24.  
  25. mysql_free_result($Recordset1);
  26. ?>
  #2 (permalink)  
Antiguo 07/10/2014, 12:34
Avatar de Mcruzmx  
Fecha de Ingreso: abril-2006
Mensajes: 357
Antigüedad: 18 años
Puntos: 9
Respuesta: No me inserta el contenido en la BD

Hola, no sé si alguien te pueda ayudar con lo que estas poniendo, pero en mi caso creo que no, te sugiero volver a redactar tu pregunta y solamente poner el código del formulario y el código con el que guardas, lo más seguro es que si un campo no te está guardando, estas poniendo mal algún nombre, pudiera ser algún error de dedo, te sugeriría copiar y pegar los nombres y seguirles el camino, cuando envies el formulario, al "recibirlo" ya sea con get o post, imprime el valor para ver si se esta pasando, y así le puedes ir siguiendo el rastro, animo.

Etiquetas: bd, contenido, html, inserta, mysql, registro, select, sql, variable
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 18:15.