Foros del Web » Programando para Internet » PHP »

Formulario

Estas en el tema de Formulario en el foro de PHP en Foros del Web. base de datos: libre tabla:menssages estructuta. id subject body to from sended_on read forder_on owner Lo que quiero es meter dos registros no uno DOS ...
  #1 (permalink)  
Antiguo 16/01/2013, 05:00
 
Fecha de Ingreso: agosto-2011
Mensajes: 165
Antigüedad: 12 años, 8 meses
Puntos: 1
Formulario

base de datos: libre
tabla:menssages
estructuta.

id
subject
body
to
from
sended_on
read
forder_on
owner

Lo que quiero es meter dos registros no uno DOS alguien sabe como.

Código PHP:
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
        <table width="487" align="center">
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Subject:</td>
            <td><input type="text" name="subject" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Body:</td>
            <td><input type="text" name="body" value="" size="32" /></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="to" value="<?php echo $row_usuario['usuario_id']; ?>" />
        <input type="hidden" name="from" value="<?php echo $row_menssages['id']; ?>" />
        <input type="hidden" name="sended_on" value="<?php echo $row_menssages['sended_on']; ?>" />
        <input type="hidden" name="read" value="0" />
        <input type="hidden" name="folder_id" value="<?php echo $row_carpetas['id']; ?>" />
        <input type="hidden" name="owner" value="<?php echo $row_menssages['id']; ?>" />
        <input type="hidden" name="MM_insert" value="form1" />
      </form>
  #2 (permalink)  
Antiguo 16/01/2013, 06:25
 
Fecha de Ingreso: septiembre-2012
Ubicación: Argentina
Mensajes: 144
Antigüedad: 11 años, 7 meses
Puntos: 12
Respuesta: Formulario

Buenas!!

queres insertar 2 veces el mismo registro??...si deseas hacer eso hace 2 veces la consulta.

es eso no?
  #3 (permalink)  
Antiguo 16/01/2013, 07:16
 
Fecha de Ingreso: agosto-2011
Mensajes: 165
Antigüedad: 12 años, 8 meses
Puntos: 1
Respuesta: Formulario

Si dos veces pero deverian de cambiar la carpeta en el primero estaria en enviados
y en el segundo registro el que recibe estaria en la bandeja de recibidos no se si me explico


mario mario 2 2 2013-01-15 12:10:34 0 2 2
mario mario 2 2 2013-01-15 12:10:34 0 1 2
  #4 (permalink)  
Antiguo 16/01/2013, 07:25
 
Fecha de Ingreso: septiembre-2012
Ubicación: Argentina
Mensajes: 144
Antigüedad: 11 años, 7 meses
Puntos: 12
Respuesta: Formulario

Bueno lo que tenes que hacer seria 2 consulta como haces siempre,

Solamente que cambias la tabla a quien realizas el Alta..

por ej.

mysqli_query("haces la consulta para Enviados");
mysqli_query("haces la consulta para Bandeja Recibidos");

Veo que el id de las carpetas son diferentes...Lo que podes hacer Folder_id restarle 1 para cuando realices la consulta sepa que tiene que hacerce el alta en Bandeja de REcibidos..

Espero que me entiendas :)
  #5 (permalink)  
Antiguo 16/01/2013, 08:40
 
Fecha de Ingreso: agosto-2011
Mensajes: 165
Antigüedad: 12 años, 8 meses
Puntos: 1
Respuesta: Formulario

Esta es toda la pagina

No entiendo bien que quieres decir

la tabla folder tiene algo asi
1 enviados
2 recibidos
3 favoritos
4 eliminados
la tabla messages te la he puesto al principio

Código PHP:
Ver original
  1. <?php require_once('Connections/libre.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. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.   $insertSQL = sprintf("INSERT INTO messages (subject, body, `to`, `from`, sended_on, `read`, folder_id, owner) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
  41.                        GetSQLValueString($_POST['subject'], "text"),
  42.                        GetSQLValueString($_POST['body'], "text"),
  43.                        GetSQLValueString($_POST['to'], "int"),
  44.                        GetSQLValueString($_POST['from'], "int"),
  45.                        GetSQLValueString($_POST['sended_on'], "date"),
  46.                        GetSQLValueString($_POST['read'], "int"),
  47.                        GetSQLValueString($_POST['folder_id'], "int"),
  48.                        GetSQLValueString($_POST['owner'], "int"));
  49.  
  50.   mysql_select_db($database_libre, $libre);
  51.   $Result1 = mysql_query($insertSQL, $libre) or die(mysql_error());
  52.  
  53.   $insertGoTo = "acceso.php";
  54.   if (isset($_SERVER['QUERY_STRING'])) {
  55.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  56.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  57.   }
  58.   header(sprintf("Location: %s", $insertGoTo));
  59. }
  60.  
  61. mysql_select_db($database_libre, $libre);
  62. $query_menssages = "SELECT * FROM messages";
  63. $menssages = mysql_query($query_menssages, $libre) or die(mysql_error());
  64. $row_menssages = mysql_fetch_assoc($menssages);
  65. $totalRows_menssages = mysql_num_rows($menssages);
  66.  
  67. mysql_select_db($database_libre, $libre);
  68. $query_usuario = "SELECT * FROM libre";
  69. $usuario = mysql_query($query_usuario, $libre) or die(mysql_error());
  70. $row_usuario = mysql_fetch_assoc($usuario);
  71. $totalRows_usuario = mysql_num_rows($usuario);
  72.  
  73. mysql_select_db($database_libre, $libre);
  74. $query_carpetas = "SELECT * FROM folders";
  75. $carpetas = mysql_query($query_carpetas, $libre) or die(mysql_error());
  76. $row_carpetas = mysql_fetch_assoc($carpetas);
  77. $totalRows_carpetas = mysql_num_rows($carpetas);
  78. ?>
  79. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  80. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/base.dwt.php" codeOutsideHTMLIsLocked="false" -->
  81. <head>
  82. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  83. <!-- InstanceBeginEditable name="doctitle" -->
  84. <title>base</title>
  85. <!-- InstanceEndEditable -->
  86. <link href="tables.css" rel="stylesheet" type="text/css" />
  87. <!-- InstanceBeginEditable name="head" -->
  88. <!-- InstanceEndEditable -->
  89. <style type="text/css">
  90. body {
  91.     background-image: url();
  92.     background-color: #D3E4E5;
  93. }
  94. .centro {
  95.     text-align: center;
  96. }
  97. irq {
  98.     text-align: left;
  99. }
  100. </style>
  101. </head>
  102.  
  103. <body bgcolor="#D3E4E5">
  104. <table width="54" border="0" align="center" cellpadding="3" cellspacing="0">
  105.   <tr>
  106.     <td align="center" valign="middle" class="centro"><img src="imagen/logo_final_.jpg" width="877" height="195" align="middle" />
  107.       <Marquee  style="font-size: 16px; color:#000"
  108. bgcolor="#B6C34F"  >
  109.     </Marquee>      <br /></td>
  110.   </tr>
  111.   <tr>
  112.     <td><!-- InstanceBeginEditable name="panel de control" -->
  113.       <p>&nbsp;</p>
  114.       <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  115.         <table width="610" align="center">
  116.           <tr valign="baseline">
  117.             <td nowrap="nowrap" align="right">Descriccion:</td>
  118.             <td><input type="text" name="subject" value="" size="50" /></td>
  119.           </tr>
  120.           <tr valign="baseline">
  121.             <td nowrap="nowrap" align="right">Texto:</td>
  122.             <td><textarea name="body" cols="50" rows="5"></textarea></td>
  123.           </tr>
  124.           <tr valign="baseline">
  125.             <td nowrap="nowrap" align="right">&nbsp;</td>
  126.             <td><input type="submit" class="rojo" value="Insertar mensaje" /></td>
  127.           </tr>
  128.         </table>
  129.         <input type="hidden" name="to" value="<?php echo $row_usuario['usuario_id']; ?>" />
  130.         <input type="hidden" name="from" value="<?php echo $row_menssages['id']; ?>" />
  131.         <input type="hidden" name="sended_on" value="<?php echo $row_menssages['sended_on']; ?>" />
  132.         <input type="hidden" name="read" value="0" />
  133.         <input type="hidden" name="folder_id" value="<?php echo $row_carpetas['id']; ?>" />
  134.         <input type="hidden" name="owner" value="<?php echo $row_menssages['id']; ?>" />
  135.         <input type="hidden" name="MM_insert" value="form1" />
  136.       </form>
  137.       <p>&nbsp;</p>
  138. <p>&nbsp;</p>
  139.     <!-- InstanceEndEditable --></td>
  140.   </tr>
  141. </table>
  142. </body>
  143. <!-- InstanceEnd --></html>
  144. <?php
  145. mysql_free_result($menssages);
  146.  
  147.  
  148. mysql_free_result($carpetas);
  149. ?>
  #6 (permalink)  
Antiguo 16/01/2013, 09:27
 
Fecha de Ingreso: septiembre-2012
Ubicación: Argentina
Mensajes: 144
Antigüedad: 11 años, 7 meses
Puntos: 12
Respuesta: Formulario

despues de hacer el primer insert
Código PHP:
Ver original
  1. $insertSQL = sprintf("INSERT INTO messages (subject, body, `to`, `from`, sended_on, `read`, folder_id, owner) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
  2. GetSQLValueString($_POST['subject'], "text"),          
  3. GetSQLValueString($_POST['body'], "text"),              
  4. GetSQLValueString($_POST['to'], "int"),                      
  5. GetSQLValueString($_POST['from'], "int"),                    
  6. GetSQLValueString($_POST['sended_on'], "date"),                      
  7. GetSQLValueString($_POST['read'], "int"),                      
  8. GetSQLValueString($_POST['folder_id'], "int"),                      
  9. GetSQLValueString($_POST['owner'], "int"));

haces lo siguiente

Código PHP:
Ver original
  1. $carpeta=1
  2.  $insertSQL = sprintf("INSERT INTO messages (subject, body, `to`, `from`, sended_on, `read`, folder_id, owner) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",                      
  3. GetSQLValueString($_POST['subject'], "text"),                      
  4.  GetSQLValueString($_POST['body'], "text"),                      
  5. GetSQLValueString($_POST['to'], "int"),                      
  6. GetSQLValueString($_POST['from'], "int"),                      
  7.  GetSQLValueString($_POST['sended_on'], "date"),                  
  8.    GetSQLValueString($_POST['read'], "int"),                      
  9. GetSQLValueString($carpeta, "int"),                    
  10.   GetSQLValueString($_POST['owner'], "int"));
  #7 (permalink)  
Antiguo 16/01/2013, 09:45
 
Fecha de Ingreso: agosto-2011
Mensajes: 165
Antigüedad: 12 años, 8 meses
Puntos: 1
Respuesta: Formulario

Perdona por mi ignorancia pero no me va

Código PHP:
$carpeta=1
$insertSQL 
sprintf("INSERT INTO messages (subject, body, `to`, `from`, sended_on, `read`, folder_id, owner) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",                       
GetSQLValueString($_POST['subject'], "text"),                      
GetSQLValueString($_POST['body'], "text"),                       
GetSQLValueString($_POST['to'], "int"),                       
GetSQLValueString($_POST['from'], "int"),                      
GetSQLValueString($_POST['sended_on'], "date"),                   
GetSQLValueString($_POST['read'], "int"),                       
GetSQLValueString($carpeta"int"),                     
GetSQLValueString($_POST['owner'], "int")); 
Si lo pongo asi me da error en la segunda fila aqui

Código PHP:
$insertSQL sprintf("INSERT INTO messages (subject, body, `to`, `from`, sended_on, `read`, folder_id, owner) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"

Última edición por yolanda16568; 16/01/2013 a las 09:55

Etiquetas: formulario, tabla, 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:16.