Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/04/2006, 17:48
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Insertar en BD

ALguien de aqui sabe como se puede realizar una aplicacion donde el usuario introduzca algo en un textbox y se ingrese a la Base de datos... encontre una forma, pero ahi solo se modifican datos ya existentes...
Yo intente hacer uno, pero solo me inserta un campo vacio..
Código PHP:
                               <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html>
<
head>
<
title>BD </title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</
head>
                    <
script language="javascript">
                    function 
nuevoAjax(){
                    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 
cargarContenido(datasource,divID){
                        var 
contenedor;
                        
contenedor document.getElementById(divID);
                        
contenedor.innerHTML '<center><img src="loader.gif" /> </center>';
                        
ajax=nuevoAjax();
                        
ajax.open("GET","bd.php",true);
                        
ajax.onreadystatechange=function() {
                         if (
ajax.readyState==4) {
                            
contenedor.innerHTML ajax.responseText
                            
}
                        }
                    
ajax.send(null)
                    }

                    
</script>
                    <style type="text/css">

                #contenedor{
                border: 5px solid #f00;
                padding: 10px;
        margin: 14px;
    }
    </style>
<body>


           <center><input type =submit value = "Manda un email" onclick ="cargarContenido('correo.html','contenedor')"></center>
               <center>Inserta tu nombre
                <input type="text" name="nombre"><br>
                <input type=submit value="ENVIAR" onclick="cargarContenido('bd.php','contenedor')"> </center>
        <div id="contenedor">
        </div>
      
</body>
</html> 
y este es el php:
Código PHP:


<?
        $con
=mysql_connect("localhost","root","passw")or die(mysql_error());
        
mysql_select_db("prueba",$con);

  
$query=mysql_query("insert into nombres (nombre) values('{$_POST['nombre']}')");

    if(
mysql_insert_id())
    {
       echo 
"Se insertaron los datos";
    }

?>