Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/03/2011, 23:24
lpcastrom
 
Fecha de Ingreso: marzo-2011
Mensajes: 1
Antigüedad: 13 años, 1 mes
Puntos: 0
registros mysql

Hola, he creado un formulario para el registro de promociones de una drogueria pero solo he podido que registre datos y necesito que tambien modifique y elimine registros desde php a mysql agradezco su colaboraci'on GRACIAS. EL CODIGO QUE TENGO ES:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Formulario ofertas</title>
<style type="text/css">
<!--
body,td,th {
font-family: Georgia, Times New Roman, Times, serif;
}
-->
</style>
</head>
<?php session_start();

//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','root','')or die ('Ha fallado la conexi&oacute;n: '.mysql_error());
mysql_select_db('sogclid')or die ('Error al seleccionar la Base de Datos: '.mysql_error());

function formRegistro(){
?>
<form action="registroprom.php" method="post">
<p>&nbsp;</p>
<table width="200" border="1" align="center">
<tr><p>
<th align="center" scope="col">Registro Ofertas</th>
</tr>
</table>
<center>
<table width="443" border="1" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="175" align="left">Drogueria</td>
<td width="250" align="left"><input name="Drogueria" type="text" id="textfield6" maxlength="30" />

</tr>
<tr>
<td width="175" align="left">Producto</td>
<td width="250" align="left"><input name="producto" type="text" id="textfield6" maxlength="30" />

</tr>

<tr>
<td align="left">Detalle</td>
<td align="left"><input name="detalle" type="text" id="textfield7" maxlength="50" /></td>
</tr>
<tr>
<td align="left">Precio</td>
<td align="left">
<input name="precio" type="text" id="textfield8" maxlength="50" />
</td>
</tr>
<tr>
<td align="left">Fecha Inicio</td>
<td align="left">
<?php
echo "<select name='ano'>";
for ($year = 2009; $year <= 2020; $year++){
echo " <option value='$year'>$year</option>";
}
echo "</select>";
echo "<select name='mes'>";
for ($month = 1; $month <= 12; $month++){
if ($month > 9){
echo " <option value='$month'>$month</option>";
} else {
echo " <option value = '0$month'>0$month</option>";
}
}
echo "</select>";
echo "<select name='dia'>";
for ($day = 1; $day <= 31; $day++){
if ($day > 9){
echo "<option value='$day'>$day</option>";
} else {
echo "<option value='0$day'>0$day</option>";
}
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td align="left">Fecha Fin</td>
<td align="left">
<?php
echo "<select name='ano'>";
for ($year = 2009; $year <= 2020; $year++){
echo " <option value='$year'>$year</option>";
}
echo "</select>";
echo "<select name='mes'>";
for ($month = 1; $month <= 12; $month++){
if ($month > 9){
echo " <option value='$month'>$month</option>";
} else {
echo " <option value = '0$month'>0$month</option>";
}
}
echo "</select>";
echo "<select name='dia'>";
for ($day = 1; $day <= 31; $day++){
if ($day > 9){
echo "<option value='$day'>$day</option>";
} else {
echo "<option value='0$day'>0$day</option>";
}
}
echo "</select>";
?> </td>
</tr>
<tr>

</table></center>
<center><p>
<input type="submit" name="Registrar" id="Registrar" value="Registrar" />
<a href="formulariomodificar.php"><input type="submit" name="Modificar" id="Modificar" value="Modificar" a href="Modificar.php" />
<input type="submit" name="Eliminar" id="Eliminar" value="Eliminar" />
</p>
<p><a href="http://www.facebook.com/pages/Sogclid/191159177583787"><img src="images (20).jpg" width="44" height="52" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</center>
<p>&nbsp;</p>
</form>
<?php
}

// verificamos si se han enviado ya las variables necesarias.
if (isset($_POST["producto"])) {
$Drogueria= $_POST["Drogueria"];
$producto= $_POST["producto"];
$detalle= $_POST["detalle"];
$precio= $_POST["precio"];

// Hay campos en blanco
if($producto==NULL|$detalle==NULL|$precio==NULL) {
echo "un campo est&aacute; vacio.";
formRegistro();
}else{





$query = 'INSERT INTO promociones (Drogueria,producto, detalle, precio, fecha_inicio, fecha_fin)
VALUES (\''.$Drogueria.'\',\''.$producto.'\',\''.$detalle .'\',\''.$precio.'\',\''.date("Y-m-d").'\',\''.date("Y-m-d").'\')';

mysql_query($query) or die(mysql_error());
echo 'El producto '.$producto.' ha sido registrado de manera satisfactoria.<br />';
echo 'Ahora puede consultarlo<br />';


}
}

else{
formRegistro();
}
?>