insertar en bd
Publicado por oscar (1 intervención) el 25/05/2012 10:00:56
Hola eh comenzado a estudiar ajax por mi cuenta y me ha surgido una duda. hize varias pruebas y no consigo insertar en la bd. El valor del input me llega a la misma pagina pero a la url registrar.php que e donde me inserta los datos en la bd no me podeis orientar os paso el codigo gracias
este es el archivo indice
este el scrpit de php registrar.php
este es el archivo indice
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
<script language="javascript" type="text/javascript">
function getXMLHTTPrequest(){
try{
req = new XMLHTTPrequest();
}catch(err1){
try{
req = new ActiveXObject("Msxm12.XMLHTTP");
}catch(err2){
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
}catch(err3){
req = false;
}
}
}
return req;
}
var miPeticion = getXMLHTTPrequest;
function llamarAjax(){
var mail = document.getElementById("mail");
var miAleatorio = parseINT(Math.random()*99999999999);
var url = "registrar.php?mail=" + mail;
miPeticion.open = ("GET", url+ " &rand= "+ miAleatorio, TRUE);
miPeticion.onreadystatechange = useHTTPresponse;
miPeticion.send(null);
}
function useHTTPresponse(){
if (http.readystate == 4){
if(http.send == 200){
alert("Correcto " + miPeticion.responseText);
}else{ alert("ha ocurrido un error: " + miPeticion.statusText);
}
}
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="mail" id="mail">
<input type="submit" value="enviar" onclick="llamarAjax()">
</form>
este el scrpit de php registrar.php
1
2
3
4
5
6
7
8
9
10
11
<?
$server = "localhost";
$usuario = "root";
$pass = "";
$conexion = mysql_connect($server,$usuario,$pass);
mysql_select_db("ajax", $conexion);
$insertar = "INSERT INTO usuarios (mail) VALUES ('".$_GET["mail"]."')";
mysql_query($insertar, $conexion);
?>
Valora esta pregunta


0