AJAX - Problemas con el valor del text input al procesar el .php

 
Vista:

Problemas con el valor del text input al procesar el .php

Publicado por Paolo (1 intervención) el 20/08/2011 04:03:43
Hola, que tal?

Estoy teniendo problemas a la hora de procesar el valor del text input por medio de ajax.

Estos son mis codigos:

ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}
 
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
 
function MostrarConsulta(datos){
	divComentarios = document.getElementById('comentarios');
	ajax=objetoAjax();
	ajax.open("POST", datos);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divComentarios.innerHTML = ajax.responseText
		}
	}
	ajax.send(null)
}


video.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!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=utf-8" />
<link href="estilo.css" rel="stylesheet" type="text/css" media="screen" />
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
 
<?php
// Aqui se conecta a la base de datos y hace las consultas necesarias  
    (isset ($_GET['id']))? $id = $_GET['id'] : $id = NULL;
        session_start();
    function conectarse($host,$usuario,$password,$BBDD){
       $link=mysql_connect($host,$usuario,$password) or die (mysql_error());
       mysql_select_db($BBDD,$link) or die (mysql_error());
       return $link;
    }
 
$link=conectarse("host","usuario","password","base_datos");
 
$video = "SELECT * FROM `videos` WHERE `video_id` = '$id'";
$video = mysql_query($video, $link);
 
$comentario = "select comment_id, comment, nombre, apellido from video_comments, usuarios where video_comments. usuario_id = usuarios.usuario_id and video_id = '$id' order by 1 desc";
$comentario = mysql_query($comentario, $link);
 
?>
<title>Videos</title>
</head>
<div id="video">
        <?php
          $rs=mysql_fetch_array($video);
            echo      "<object style='height: 200px; width: 400px'>"
                    ."<param name='movie' value='http://www.youtube.com/v/" .$rs['url']. "'>"
                    ."<param name='allowFullScreen' value='true'>"
                    ."<param name='allowScriptAccess' value='always'>"
                    ."<embed src='http://www.youtube.com/v/" .$rs['url']. "' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='390'>"
                    ."</object>";
        ?>
</div>
 
 
<div id="comentarios">
    <?php
        while($rs=mysql_fetch_array($comentario))
          {
            echo         "" .$rs['nombre']. " " .$rs['apellido']. ": " .$rs['comment']. "<br />";
          }
    ?>
</div>
 
 
<div id="añadir_comentarios">
    <form name="consulta" action="" onsubmit="MostrarConsulta('anadir_comentario.php'); return false">
    <input type="text" name="comment" value="" />
    <input type="text" name="id" value="40" />
    <input type="submit" value="Add" />
    </form>
</div>
</body>
</html>


anadir_comentario.php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
session_start();
 
$con = mysql_connect("host","usuario","password");
 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("base_datos", $con);
 
$comentarios="INSERT INTO video_comments (comment_id, usuario_id, video_id, comment)
VALUES  
('','$_SESSION[usuario]','$_POST[id]','$_POST[comment]')";
 
if (!mysql_query($comentarios,$con))
  {
  die('Error: ' . mysql_error());
  }
 
mysql_close($con);
 
?>


A la hora de añadir el comentario con el anadir_comentario.php no reconoce los valores de $_POST[id] ni el de $_POST[comment], como hago para llamar a los valores de los text inputs del video.php desde el anadir_comentarios.php para que los reconozca?

Muchisimas gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Problemas con el valor del text input al procesar el .php

Publicado por jhon jairo (3 intervenciones) el 12/09/2011 19:43:44
amigo cuando se van a enviar valores alfabeticos o alfanumericos debes adecuar la variable para que asi sus valores sean reconocidos, esto se hace con comillas de esta forma.
'".$_POST[id]."','". $_POST[comment]."'

o tambien asi.

"'".$_POST[id]."'" ,$_POST[comment]
espero que sea eso.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar