Ver Mensaje Individual
  #12 (permalink)  
Antiguo 16/12/2009, 13:34
visona
 
Fecha de Ingreso: febrero-2008
Mensajes: 675
Antigüedad: 16 años, 3 meses
Puntos: 5
Respuesta: INSERTE desde un link

Pues no me funciona
esto es lo que tengo antes del </head>
Código PHP:
<script type="text/javascript">
#
function Ajax(){
#
    
var xmlhttp false
#
    
if (window.XMLHttpRequest) {// Si es IE7, Mozilla, Safari etc
#
        
xmlhttp = new XMLHttpRequest();
#
    
} else if (window.ActiveXObject){ // pero si es IE6
#
        
try {
#
            
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
#
        
}
#
        
catch (e){ // en caso que sea una versión más antigua
#
            
try{
#
                
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
#
            
}catch (e){}
#
        
}
#
    
}
#
    
if(!xmlhttp){
#
        
alert("Error: Este navegador no soporte al objeto XMLHTTP");
#
    
}
#
    
return xmlhttp;
#
}  
#
 
#
function insertar(dato){
#
    
var ajax=Ajax();

    
ajax.open("GET""insertar.php?dato="+datotrue);

    
ajax.send(null);

}  

</script> 
Y esto en el insertar.php
Código PHP:
<?php
$recibido
=$_GET['dato']; 
mysql_connect("localhost","usuario","******");
mysql_select_db("mi_BD"); 
mysql_query("INSERT INTO megustas (usuario_me) VALUES ('$recibido')");

?>
Si cargo la pagina quitando el ('$recibido')y poniendo ('1') me inserta el 1 con lo cual funciona. pero cuando le doy al enlace, no me inserta nada.
Esto es lo que tengo en el link
Código PHP:
<a href="javascript:insertar('<?php echo $row_userpiensa['id_gente']; ?>')">ME GUSTA</a>
y si pongo encima del link el raton, me muestra que sale el dato que le pido.

Donde puede estar el fallo?