Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: David Vans en 21 Septiembre 2007, 14:43 pm



Título: Pasra Varibles en el mismo documento php con java script
Publicado por: David Vans en 21 Septiembre 2007, 14:43 pm
Código:
function ComprobarNombre(){

datos = document.registro.b_comprobar.value;

<?php
$link= mysql_connect("localhost", "BD","Passw");
mysql_select_db("Mybd", $link);
$result = mysql_query("select count  from usuarios where nombre_cuenta=Datos;", $link);

?>
}

Lo que queria es pasar la varible datos que esta en javascript al codigo en php


Título: Re: Pasra Varibles en el mismo documento php con java script
Publicado por: дٳŦ٭ en 21 Septiembre 2007, 14:50 pm
Con javascript manda la variable por get, la recibes con PHP ($_GET) y ejecutas el query.

Suerte


Título: Re: Pasra Varibles en el mismo documento php con java script
Publicado por: David Vans en 21 Septiembre 2007, 16:46 pm
Es indispensble enviarlas por url


Título: Re: Pasra Varibles en el mismo documento php con java script
Publicado por: alone-in-the-chat en 21 Septiembre 2007, 18:20 pm
Si no deseas enviarla por la url podrias implementar un poco de ajax le envias la variables que sacas del formulario a un script para que la procese y te devuelva el resultado eso sin recargar toda la pagina.

Seria algo asi


Código
  1. function objetus(){try {MIobjetus = new ActiveXObject("Msxml2.XMLHTTP");}catch (e) {try {MIobjetus= new ActiveXObject("Microsoft.XMLHTTP"); }catch (E) {MIobjetus= false;}}if (!MIobjetus && typeof XMLHttpRequest!='undefined'){MIobjetus = new XMLHttpRequest();}return MIobjetus;}
  2. function addItem(id)
  3. {
  4.  
  5. var ajax;
  6. ajax = new objetus();
  7. var _values_send="param="+ id
  8. var _URL_=  url + "include/handler.php" ;
  9. ajax.open("POST",_URL_,true);
  10. ajax.onreadystatechange=function()
  11. {        
  12. if (ajax.readyState==1){
  13. }else if(ajax.readyState==4){
  14. try {
  15.            if(ajax.status==200)
  16. {
  17. //acciones
  18. }
  19. }catch(E){
  20. alert(E);
  21. }
  22. }
  23. }
  24. ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  25. ajax.send(_values_send);
  26. delete(ajax);
  27. }
  28.  
  29.  

Buscando puedes encontrar bastante informacion de ajax y como implementarlo


Saludos