Insertar datos a MYSQL
Publicado por israel (1 intervención) el 23/09/2011 21:58:57
actualmente cuanto con una base de datos con datos al cual hago llenar con un formulario y lo que hace es llenar toda la fila en mi MySQL con el update cuando solo quiero llenar solo un registro al comparar con un usuario que sea igual no todo los registros. como puedo hacerle para que compare un por uno hasta que llege al adecuado e inserte el registro.
codigo
<?php
include ("conexion.php");
// dar clic al boton agregar
if ($_REQUEST['agregar'] != ""){
$msql = mysql_query("SELECT Chequera,Empresas,RFC,Banco,Cuenta,IniFolio,FinFolio,FRestante,NomEjecutivo,Status FROM Chequeras ORDER BY FinFolio ASC");
while ($row = mysql_fetch_array($msql, MYSQL_ASSOC)){
//Compara la cantida y restarle la cantidad de que va ser ocupada.
if ($row['Empresas'] == $_POST['empresa'])
{
$GFolio = $row['FinFolio'] - $_POST['folio'];
$sql = "UPDATE Chequeras SET FRestante='$GFolio'";
mysql_query ($sql);
if ($GFolio<=15 && $GFolio > 0 ){
?>
<script>
// lanzar un alerta que necesita pedir al banco mas cheques
alert ("Se necesita una nueva Chequera");
</script>
<?
} // Fin de if
else{
echo "<br>";
echo "no agregar";
}
*/
echo "<br>";
echo "sale del if";
} // Fin de If
echo "<br>";
echo "<br>";
echo "siguiente ciclo while";
}
}
?>
------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
include ("conexion.php");
include ("GFolio.php");
?>
</head>
<body>
<form name="folio" action="" method="post">
<table>
<tr>
<td>
Empresa:
</td>
<td>
<select name="empresa" value="seleccion" tabindex="msql">
<?php
?>
<? echo $msql = mysql_query("SELECT Empresas,FinFolio FROM Chequeras ORDER BY Empresas ASC");
while ($row = mysql_fetch_array($msql,MYSQL_ASSOC)) {
echo '<option value="'.$row["Empresas"].'">'.$row["Empresas"].'</option>';
} mysql_free_result($msql); ?>
</select>
</td>
</tr>
<tr>
<td>
cuantos folio:
</td>
<td>
<input name="folio" type="text">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Aceptar" name="agregar">
<input type="submit" value="Aceptar" name="BORRAR">
</td>
</tr>
</table>
</form>
</body>
</html>
codigo
<?php
include ("conexion.php");
// dar clic al boton agregar
if ($_REQUEST['agregar'] != ""){
$msql = mysql_query("SELECT Chequera,Empresas,RFC,Banco,Cuenta,IniFolio,FinFolio,FRestante,NomEjecutivo,Status FROM Chequeras ORDER BY FinFolio ASC");
while ($row = mysql_fetch_array($msql, MYSQL_ASSOC)){
//Compara la cantida y restarle la cantidad de que va ser ocupada.
if ($row['Empresas'] == $_POST['empresa'])
{
$GFolio = $row['FinFolio'] - $_POST['folio'];
$sql = "UPDATE Chequeras SET FRestante='$GFolio'";
mysql_query ($sql);
if ($GFolio<=15 && $GFolio > 0 ){
?>
<script>
// lanzar un alerta que necesita pedir al banco mas cheques
alert ("Se necesita una nueva Chequera");
</script>
<?
} // Fin de if
else{
echo "<br>";
echo "no agregar";
}
*/
echo "<br>";
echo "sale del if";
} // Fin de If
echo "<br>";
echo "<br>";
echo "siguiente ciclo while";
}
}
?>
------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
include ("conexion.php");
include ("GFolio.php");
?>
</head>
<body>
<form name="folio" action="" method="post">
<table>
<tr>
<td>
Empresa:
</td>
<td>
<select name="empresa" value="seleccion" tabindex="msql">
<?php
?>
<? echo $msql = mysql_query("SELECT Empresas,FinFolio FROM Chequeras ORDER BY Empresas ASC");
while ($row = mysql_fetch_array($msql,MYSQL_ASSOC)) {
echo '<option value="'.$row["Empresas"].'">'.$row["Empresas"].'</option>';
} mysql_free_result($msql); ?>
</select>
</td>
</tr>
<tr>
<td>
cuantos folio:
</td>
<td>
<input name="folio" type="text">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Aceptar" name="agregar">
<input type="submit" value="Aceptar" name="BORRAR">
</td>
</tr>
</table>
</form>
</body>
</html>
Valora esta pregunta


0