Estoy intentando crear un PHP en el que al darle al botón guardar se guarde la información en una base de datos.
Es la primera vez que me aventuro a hacer un problemita así, de manera que voy un poco perdida en cuanto a solución de los errores que aparecen.
Si podéis echarle un vistazo, éste es el código.
La condición depende del campo codigo que dependiendo de si se introduce el código del cliente se crea uno nuevo o se modifica el existente.
Código HTML:
<div class="contenedor_contenidos"> <?php if($_REQUEST[codigo]=="-") { $conexion=mysql_connect("localhost","root","") or die("Problemas en la conexion"); mysql_select_db("clientes",$conexion) or die("Problemas en la seleccion de la base de datos"); mysql_query("insert into clientes(nombre,cif,direccion,codigo_postal,ciudad,telefono,fax,email,fecha_alta) values ('$_REQUEST[nombre]','$_REQUEST[cif]','$_REQUEST[direccion]','$_REQUEST[cp]','$_REQUEST[ciudad]','$_REQUEST[telefono]','$_REQUEST[fax]','$_REQUEST[email]',date(d/m/y))", $conexion) or die("Problemas en el select".mysql_error()); mysql_close($conexion); echo "El cliente ha sido añadido."; } else { $conexion=mysql_connect("localhost","root","") or die("Problemas en la conexion"); mysql_select_db("clientes",$conexion) or die("Problemas en la selección de la base de datos"); $registros=mysql_query("select * from clientes where nombre='$_REQUEST[nombre]'",$conexion) or die("Problemas en el select:".mysql_error()); if ($reg=mysql_fetch_array($registros)) { $registros=mysql_query("update clientes set cif='$_REQUEST[mailnuevo]' where nombre='$_REQUEST[nombre]'",$conexion) or die("Problemas en el select:".mysql_error()); echo "El mail fue modificado con exito"; } ?> <div class="contenidos"><br/><br/><br/><form style="margin-left:200px;" method="post" action="guardar-cliente.php"> Código: <input type="text" name="codigo" size="20" value="-"> <span style="margin-left:190px;" >Núm. albaranes: <input type="text" name="num_albaranes" size="20" value="0"/></span> <br/><br/><br/> <button type="submit">Nombre: </button> <input type="text" name="nombre" size="60"> <span style=" margin-left:10px;" >CIF: <input type="text" name="cif" size="20" /></span> <br/><br/><br/> Dirección: <input type="text" name="direccion" size="50" /><br/><br/> C.P.: <input type="text" name="cp" size="10" /> <span style="margin-left:10px;">Ciudad: <input type="text" name="ciudad" size="30" /></span> <br/><br/><br/> Teléfono: <input type="text" name="telefono" size="20" /> <span style="margin-left:20px;">Fax: <input type="text" name="fax" size="20" /></span><br/><br/> E-mail: <input type="text" name="email" size="55" /> <br/><br/> <span style="margin-left:420px;">Fecha de alta: <input type="text" name="fecha_alta" value="dd/mm/aa"/></span><br/><br/> <span style="margin-left:280px;"><button type="submit"><br/>Guardar<br/><br/></button> <button type="reset"><br/> Borrar <br/><br/></button></span> </form></div>