CLIENTES.php
Código PHP:
<html>
<head>
<title>agregar clientes</title>
</head>
<body>
<p> </p>
<?php
error_reporting(0);
?>
<?
if($_POST[enviar]) {
require 'config.php' ;
function quitar($texto) {
$texto = trim($texto) ;
$texto = htmlspecialchars($texto) ;
$texto = str_replace(chr(160),'',$texto) ; # Elimina espacios que no pueden ser borrados por trim()
return $texto ;
}
$codigo = $_POST['codigo'];
$con = mysql_query("select * from clientes where codigo='$codigo'") ;
if(mysql_result($con,0,0)) {
echo 'El cliente ya existe en la base de datos. Haz click <a href="javascript:history.back(-1)">aquí</a> para regresar.' ;
}
else {
$nombre = $_POST['nombre'];
$direccion = $_POST['direccion'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$pedidos = $_POST['pedidos'];
mysql_query("INSERT INTO clientes (codigo, nombre, direccion, email, telefono, pedidos) VALUES('$codigo','$nombre','$direccion','$email','$telefono','$pedidos')");
echo 'La informacion sobre el cliente $codigo ha sido guardada,Señora carmen';
}
}
else {
?>
<script>
function comprobar() {
if(formulario.codigo.value.length < 1) {
alert('El Codigo del cliente esta mal puesto.') ;
return false ;
}
if(formulario.nombre.value.length < 1) {
alert('no es mejor k l epongas un nombre al codigo? para saber kien es y eso xd.') ;
return false ;
}
if(formulario.telefono.value.lenght < 9) {
alert('Creo que no pusistes bien el telefono,revisalo anda') ;
return false ;
}
if(formulario.pedidos.value.lenght < 1) {
alert('Pero antes de guardar,añade los pedidos no??') ;
return false ;
}
}
</script>
<form name="formulario" method="post" action="<?=$_SERVER[PHP_SELF]?>" onSubmit="return comproban()">
<p><b>Codigo:</b><br>
<input type="text" name="codigo" maxlength="3"><br>
<b>Nombre Cliente:</b><br>
<input type="text" name="nombre" maxlength="50"><br>
<b>Direccion:</b><br>
<input type="text" name="direccion" maxlength="50"><br>
<b>Email:</b><br>
<input type="text" name="email" maxlength="40"><br>
<b>Telefono:</b><br>
<input type="text" name="telefono" maxlength="9"><br>
<b>Pedidos:</b><br>
<textarea name="pedidos" id="456" cols="45" rows="5"></textarea>
<br>
<input type="submit" name="enviar" value="Registrar">
</p>
</form>
</div>
<?
}
?>
</body>
</html>
Código PHP:
<html>
<head>
</head>
<body>
<?
//Inicializamos variables de conexión
$host="localhost";
$user="root";
$passwd="11021895";
$db="test2";
//Creamos la conexión
$link = mysql_connect($host, $user, $passwd);
mysql_select_db($db, $link);
//primero hacemos una consulta para listar uno de tus productos
//y del resultado los metemos a un campo de texto para poder modificarlos
$sql=mysql_query("select * from clientes ORDER BY codigo", $link);
//Preguntamos si nuestra consulta da algun resultado
while ($row=mysql_fetch_array($sql))
{
echo "<html>
<head>
<title>mostrar</title>
</head>
<body bgcolor='#FFFFCC'>
<form>
";
$row_=mysql_fetch_array($sql);
echo "<br>";
echo "<table align='center' border='1' align='center' bordercolor='#000000'>";
echo "
<tr>
<th>Codigo</th>
<th>Nombre</th>
<th>Direccion</th>
<th>Telefono</th>
<th>E-mail</th>
<th>Pedidos</th>
</tr>
";
echo "<tr>";
echo "<td><input type='text' name='h' value='".$row['codigo']."' disabled readonly autocomplete='on'></td>";
echo "<td class='tabla'><input type='text' name='valor1' value='".$row['nombre']."'></td>";
print "<td class='tabla'><input type='text' name='valor2' value='".$row['telefono']."'></td>";
echo "<td><input type='text' name='valor3' value='".$row['direccion']."'></td>";
echo "<td><input type='text' name='valor4' value='".$row['email']."'></td>";
echo "<td><input type='text' name='valor5' value='".$row['pedidos']."'></td>";
echo "</form></table>";
echo "</body></html>";
}
?>
![](http://img208.imageshack.us/img208/9210/sqlp.png)