Foros del Web » Programando para Internet » PHP »

Funcion no funciona

Estas en el tema de Funcion no funciona en el foro de PHP en Foros del Web. Hola, esto me guarda los datos en los campos id, from, to, message, sent y recd, el problema es que me guarda todos los campos ...
  #1 (permalink)  
Antiguo 23/05/2010, 14:15
Avatar de joska1993  
Fecha de Ingreso: septiembre-2009
Mensajes: 76
Antigüedad: 14 años, 7 meses
Puntos: 0
Funcion no funciona

Hola, esto me guarda los datos en los campos id, from, to, message, sent y recd, el problema es que me guarda todos los campos menos el campo from, que puede ser?

Les dejo este codigo porque estoy casi seguro que el fallo es de esta funcion.

Código PHP:
function sendChat() {
    
$from $_SESSION['usuario'];
    
$to $_POST['to'];
    
$message $_POST['message'];

    
$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s'time());
    
    
$messagesan sanitize($message);

    if (!isset(
$_SESSION['chatHistory'][$_POST['to']])) {
        
$_SESSION['chatHistory'][$_POST['to']] = '';
    }

    
$_SESSION['chatHistory'][$_POST['to']] .= <<<EOD
                       {
            "s": "1",
            "f": "
{$to}",
            "m": "
{$messagesan}"
       },
EOD;


    unset(
$_SESSION['tsChatBoxes'][$_POST['to']]);

    
$sql "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())";
    
$query mysql_query($sql);
    echo 
"1";
    exit(
0);

Espero que puedan ayudarme, cualquier comentario me podria ser de gran ayuda, Gracias!
  #2 (permalink)  
Antiguo 23/05/2010, 14:35
 
Fecha de Ingreso: diciembre-2009
Mensajes: 612
Antigüedad: 14 años, 4 meses
Puntos: 16
Respuesta: Funcion no funciona

Una pregunta, que es lo que hace EOD? :S
__________________
Tengo una pregunta que a veces me tortura... ¿El loco soy yo o los locos son los demás?
  #3 (permalink)  
Antiguo 23/05/2010, 14:37
Avatar de joska1993  
Fecha de Ingreso: septiembre-2009
Mensajes: 76
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Funcion no funciona

Cita:
Iniciado por millan2525 Ver Mensaje
Una pregunta, que es lo que hace EOD? :S
esto

http://php.net/manual/en/language.types.string.php
  #4 (permalink)  
Antiguo 23/05/2010, 14:42
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 3 meses
Puntos: 126
Respuesta: Funcion no funciona

Hola

Prueba con session_star()

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #5 (permalink)  
Antiguo 23/05/2010, 14:45
Avatar de joska1993  
Fecha de Ingreso: septiembre-2009
Mensajes: 76
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Funcion no funciona

sigue sin funcionar...

Código PHP:
Ver original 

ya lo tenia puesto al principio del code, antes de esta funcion, pero el problema es que me guarda todos los datos menos el from...

no se que puede pasar...
  #6 (permalink)  
Antiguo 23/05/2010, 15:00
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 3 meses
Puntos: 126
Respuesta: Funcion no funciona

Hola

Intenta ha hacer una prueba de escritorio para ver que realmente se está enviando. Quizás eso arroje algo de luz

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #7 (permalink)  
Antiguo 23/05/2010, 15:01
Avatar de joska1993  
Fecha de Ingreso: septiembre-2009
Mensajes: 76
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Funcion no funciona

si, ya lo consegui, pero ahora ocurre otro problema, y es que no me deja desplazar la barra lateral de la pagina la barra de scroll, que puede ser?

Código PHP:
Ver original
  1. <?php
  2.  
  3. define ('DBPATH', '*********');
  4. define ('DBUSER', '******');
  5. define ('DBPASS', '*****');
  6. define ('DBNAME', '******');
  7.  
  8. require_once 'functions.inc.php';
  9. $_SESSION['username'] = $user->userData['usuario'];
  10.  
  11. global $dbh;
  12. $dbh = mysql_connect(DBPATH,DBUSER,DBPASS);
  13. mysql_selectdb(DBNAME,$dbh);
  14.  
  15. if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); }
  16. if ($_GET['action'] == "sendchat") { sendChat(); }
  17. if ($_GET['action'] == "closechat") { closeChat(); }
  18. if ($_GET['action'] == "startchatsession") { startChatSession(); }
  19.  
  20. if (!isset($_SESSION['chatHistory'])) {
  21.     $_SESSION['chatHistory'] = array();
  22. }
  23.  
  24. if (!isset($_SESSION['openChatBoxes'])) {
  25.     $_SESSION['openChatBoxes'] = array();  
  26. }
  27.  
  28. function chatHeartbeat() {
  29.    
  30.     $sql = "select * from chat where (chat.to = '".mysql_real_escape_string($_SESSION['username'])."' AND recd = 0) order by id ASC";
  31.     $query = mysql_query($sql);
  32.     $items = '';
  33.  
  34.     $chatBoxes = array();
  35.  
  36.     while ($chat = mysql_fetch_array($query)) {
  37.  
  38.         if (!isset($_SESSION['openChatBoxes'][$chat['from']]) && isset($_SESSION['chatHistory'][$chat['from']])) {
  39.             $items = $_SESSION['chatHistory'][$chat['from']];
  40.         }
  41.  
  42.         $chat['message'] = sanitize($chat['message']);
  43.  
  44.         $items .= <<<EOD
  45.                        {
  46.             "s": "0",
  47.             "f": "{$chat['from']}",
  48.             "m": "{$chat['message']}"
  49.        },
  50. EOD;
  51.  
  52.     if (!isset($_SESSION['chatHistory'][$chat['from']])) {
  53.         $_SESSION['chatHistory'][$chat['from']] = '';
  54.     }
  55.  
  56.     $_SESSION['chatHistory'][$chat['from']] .= <<<EOD
  57.                            {
  58.             "s": "0",
  59.             "f": "{$chat['from']}",
  60.             "m": "{$chat['message']}"
  61.        },
  62. EOD;
  63.        
  64.         unset($_SESSION['tsChatBoxes'][$chat['from']]);
  65.         $_SESSION['openChatBoxes'][$chat['from']] = $chat['sent'];
  66.     }
  67.  
  68.     if (!empty($_SESSION['openChatBoxes'])) {
  69.     foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) {
  70.         if (!isset($_SESSION['tsChatBoxes'][$chatbox])) {
  71.             $now = time()-strtotime($time);
  72.             $time = date('g:iA M dS', strtotime($time));
  73.             $time222 = date('H:i:s', strtotime($time));
  74.  
  75.             $message = "Enviado a las ".$time22."";
  76.             if ($now > 180) {
  77.                 $items .= <<<EOD
  78. {
  79. "s": "2",
  80. "f": "$chatbox",
  81. "m": "{$message}"
  82. },
  83. EOD;
  84.  
  85.     if (!isset($_SESSION['chatHistory'][$chatbox])) {
  86.         $_SESSION['chatHistory'][$chatbox] = '';
  87.     }
  88.  
  89.     $_SESSION['chatHistory'][$chatbox] .= <<<EOD
  90.         {
  91. "s": "2",
  92. "f": "$chatbox",
  93. "m": "{$message}"
  94. },
  95. EOD;
  96.             $_SESSION['tsChatBoxes'][$chatbox] = 1;
  97.         }
  98.         }
  99.     }
  100. }
  101.  
  102.     $sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($_SESSION['username'])."' and recd = 0";
  103.     $query = mysql_query($sql);
  104.  
  105.     if ($items != '') {
  106.         $items = substr($items, 0, -1);
  107.     }
  108. header('Content-type: application/json');
  109. ?>
  110. {
  111.         "items": [
  112.             <?php echo $items;?>
  113.         ]
  114. }
  115.  
  116. <?php
  117.             exit(0);
  118. }
  119.  
  120. function chatBoxSession($chatbox) {
  121.    
  122.     $items = '';
  123.    
  124.     if (isset($_SESSION['chatHistory'][$chatbox])) {
  125.         $items = $_SESSION['chatHistory'][$chatbox];
  126.     }
  127.  
  128.     return $items;
  129. }
  130.  
  131. function startChatSession() {
  132.     $items = '';
  133.     if (!empty($_SESSION['openChatBoxes'])) {
  134.         foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) {
  135.             $items .= chatBoxSession($chatbox);
  136.         }
  137.     }
  138.  
  139.  
  140.     if ($items != '') {
  141.         $items = substr($items, 0, -1);
  142.     }
  143.  
  144. header('Content-type: application/json');
  145. ?>
  146. {
  147.         "username": "<?php echo $_SESSION['username'];?>",
  148.         "items": [
  149.             <?php echo $items;?>
  150.         ]
  151. }
  152.  
  153. <?php
  154.  
  155.  
  156.     exit(0);
  157. }
  158.  
  159. function sendChat() {
  160.     $from = $_SESSION['username'];
  161.     $to = $_POST['to'];
  162.     $message = $_POST['message'];
  163.  
  164.     $_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());
  165.    
  166.     $messagesan = sanitize($message);
  167.  
  168.     if (!isset($_SESSION['chatHistory'][$_POST['to']])) {
  169.         $_SESSION['chatHistory'][$_POST['to']] = '';
  170.     }
  171.  
  172.     $_SESSION['chatHistory'][$_POST['to']] .= <<<EOD
  173.                        {
  174.             "s": "1",
  175.             "f": "{$to}",
  176.             "m": "{$messagesan}"
  177.        },
  178. EOD;
  179.  
  180.  
  181.     unset($_SESSION['tsChatBoxes'][$_POST['to']]);
  182.  
  183.     $sql = "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())";
  184.     $query = mysql_query($sql);
  185.     echo "1";
  186.     exit(0);
  187. }
  188.  
  189. function closeChat() {
  190.  
  191.     unset($_SESSION['openChatBoxes'][$_POST['chatbox']]);
  192.    
  193.     echo "1";
  194.     exit(0);
  195. }
  196.  
  197. function sanitize($text) {
  198.     $text = htmlspecialchars($text, ENT_QUOTES);
  199.     $text = str_replace("\n\r","\n",$text);
  200.     $text = str_replace("\r\n","\n",$text);
  201.     $text = str_replace("\n","<br>",$text);
  202.     return $text;
  203. }
  204.  
  205. ?>

Etiquetas: chat, post
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:43.