hola amigos por favor ayudenme no me guarda los datos, muchas gracias de antemano, aqui va mi codigo:
index.php
<?php
if (isset($_POST['submit']))
{
include 'db.php';
$Vendedor=$_POST['Vendedor'] ;
$Semana= $_POST['Semana'] ;
$QuienPago=$_POST['QuienPago'] ;
$Proveedor=$_POST['Proveedor'] ;
$Fecha=$_POST['Fecha'] ;
$Control=$_POST['Control'] ;
$Adelanto=$_POST['Adelanto'] ;
$Cotizacion=$_POST['Cotizacion'] ;
$Año=$_POST['Año'] ;
$Tipo=$_POST['Tipo'] ;
$Cliente=$_POST['Cliente'] ;
$Descripcion=$_POST['Descripcion'] ;
$Factura=$_POST['Factura'] ;
$MontoTotal=$_POST['MontoTotal'] ;
$MontoTotal2=$_POST['MontoTotal2'] ;
$Factura2=$_POST['Factura2'] ;
mysql_query("ALTER TABLE servicio AUTO_INCREMENT=1");
mysql_query("INSERT INTO `servicio`(Vendedor,Semana,QuienPago,Proveedor,Fecha,Control,Adelanto,Cotizacion,Año,Tipo,Cliente,Descripcion,Factura,MontoTotal,MontoTotal2,Factura2)
VALUES ('$Vendedor','$Semana','$QuienPago','$Proveedor''$Fecha','$Control','$Adelanto','$Cotizacion''$Año','$Tipo','$Cliente','$Descripcion''$Factura','$MontoTotal','$MontoTotal2','$Factura2')");
}
?>
<?php
include("db.php");
$result=mysql_query("SELECT * FROM servicio");
while($test = mysql_fetch_array($result))
{
$id = $test['id'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['id']."</font></td>";
echo"<td><font color='black'>" .$test['Vendedor']."</font></td>";
echo"<td><font color='black'>". $test['Semana']. "</font></td>";
echo"<td><font color='black'>". $test['QuienPago']. "</font></td>";
echo"<td><font color='black'>". $test['Proveedor']. "</font></td>";
echo"<td><font color='black'>" .$test['Fecha']."</font></td>";
echo"<td><font color='black'>" .$test['Control']."</font></td>";
echo"<td><font color='black'>". $test['Adelanto']. "</font></td>";
echo"<td><font color='black'>". $test['Cotizacion']. "</font></td>";
echo"<td><font color='black'>". $test['Año']. "</font></td>";
echo"<td><font color='black'>" .$test['Tipo']."</font></td>";
echo"<td><font color='black'>" .$test['Cliente']."</font></td>";
echo"<td><font color='black'>". $test['Descripcion']. "</font></td>";
echo"<td><font color='black'>". $test['Factura']. "</font></td>";
echo"<td><font color='black'>". $test['MontoTotal']. "</font></td>";
echo"<td><font color='black'>". $test['MontoTotal2']. "</font></td>";
echo"<td><font color='black'>". $test['Factura2']. "</font></td>";
echo"<td> <a href ='view.php?id=$id'><strong>Editar</strong></a>";
echo"<td> <a href ='del.php?id=$id'><strong>Eliminar<strong></a>";
echo "</tr>";
}
mysql_close($conn);
?>
</table>
view.php
<?php
require("db.php");
$id =$_REQUEST['id'];
$result = mysql_query("SELECT * FROM servicio WHERE id = '$id'");
$test = mysql_fetch_array($result);
if (!$result)
{
die("Error: No existe la data");
}
$Vendedor=$test['Vendedor'] ;
$Semana= $test['Semana'] ;
$QuienPago=$test['QuienPago'] ;
$Proveedor=$test['Proveedor'] ;
$Fecha=$test['Fecha'] ;
$Control= $test['Control'] ;
$Adelanto=$test['Adelanto'] ;
$Cotizacion=$test['Cotizacion'] ;
$Año=$test['Año'] ;
$Tipo= $test['Tipo'] ;
$Cliente=$test['Cliente'] ;
$Descripcion=$test['Descripcion'] ;
$Factura=$test['Factura'] ;
$MontoTotal= $test['MontoTotal'] ;
$MontoTotal2=$test['MontoTotal2'] ;
$Factura2=$test['Factura2'] ;
if(isset($_POST['save']))
{
$Vendedor_save=$_POST['Vendedor'] ;
$Semana_save= $_POST['Semana'] ;
$QuienPago_save=$_POST['QuienPago'] ;
$Proveedor_save=$_POST['Proveedor'] ;
$Fecha_save=$_POST['Fecha'] ;
$Control_save=$_POST['Control'] ;
$Adelanto_save=$_POST['Adelanto'] ;
$Cotizacion_save=$_POST['Cotizacion'] ;
$Año_save=$_POST['Año'] ;
$Tipo_save=$_POST['Tipo'] ;
$Cliente_save=$_POST['Cliente'] ;
$Descripcion_save=$_POST['Descripcion'] ;
$Factura_save=$_POST['Factura'] ;
$MontoTotal_save=$_POST['MontoTotal'] ;
$MontoTotal2_save=$_POST['MontoTotal2'] ;
$Factura2_save=$_POST['Factura2'] ;
mysql_query("UPDATE servicio SET Vendedor ='$Vendedor_save', Semana ='$Semana_save',
QuienPago ='$QuienPago_save',Proveedor ='$Proveedor_save',Fecha ='$Fecha_save,Control ='$Control_save,Adelanto ='$Adelanto_save,Cotizacion ='$Cotizacion_save,Año ='$Año_save,Tipo ='$Tipo_save,Cliente ='$Cliente_save,Descripcion ='$Descripcion_save,Proveedor ='$Proveedor_save,Factura ='$Factura_save,MontoTotal ='$MontoTotal_save,MontoTotal2 ='$MontoTotal2_save,Factura2 ='$Factura2_save WHERE id = '$id'")
or die(mysql_error());
echo "Guardado!";
}
mysql_close($conn);
?>
Te falto una coma:
VALUES ('$Vendedor','$Semana','$QuienPago','$Proveedor''$Fecha','$Control','$Adelanto','$Cotizacion''$Año','$Tipo','$Cliente','$Descripcion''$Factura','$MontoTotal','$MontoTotal2','$Factura2')");
Entre $Cotizacion y $Año...
Y no estoy completamente seguro de esto pero $Año parece ser que no es el nombre de una variable valida.
sigue sin funcionarme...
Sin ningun error? primero fijate si conecta.. muestra db.php.
http://php.net//manual/es/function.mysql-connect.php
Cita de: shitoman en 30 Julio 2014, 02:17 AM
sigue sin funcionarme...
Debería lanzarte algún error, tienes habilitado el error_reporting?
error_reporting(E_ALL);
Al principio.
no lanza ningun error, ni siquiera agregandole esa funcion
Cita de: shitoman en 30 Julio 2014, 03:09 AM
no lanza ningun error, ni siquiera agregandole esa funcion
Prueba así:
ini_set("display_errors", 1);
error_reporting(E_ALL);
fijate index.php no me marca ningun error relleno los campos y cuando presiono el boton agregar simplemente no hace nada osea no funciona, en cambio cuando entro en view.php y relleno los campos y presiono guardar me sale:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '100,Adelanto ='1500,Cotizacion ='2000,Año =',Tipo =',Cliente =',Descripcion =',F' at line 2"
Cita de: shitoman en 30 Julio 2014, 03:42 AM
fijate index.php no me marca ningun error relleno los campos y cuando presiono el boton agregar simplemente no hace nada osea no funciona, en cambio cuando entro en view.php y relleno los campos y presiono guardar me sale:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '100,Adelanto ='1500,Cotizacion ='2000,Año =',Tipo =',Cliente =',Descripcion =',F' at line 2"
Hay un errro con las comillas:
Fecha ='$Fecha_save,Control ='$Control_save,Adelanto ='$Adelanto_save,Cotizacion ='$Cotizacion_save,Año ='$Año_save,Tipo ='$Tipo_save,Cliente ='$Cliente_save,Descripcion ='$Descripcion_save,Proveedor ='$Proveedor_save,Factura ='$Factura_save,MontoTotal ='$MontoTotal_save,MontoTotal2 ='$MontoTotal2_save,Factura2 ='$Factura2_save
Fijate como no cierras las comillas, las dejas abiertas.
Y habría que revisar los errores mysql de index.php.
Agrega:
or die(mysql_error());
Por ejemplo:
mysql_query("ALTER TABLE servicio AUTO_INCREMENT=1");
por:
mysql_query("ALTER TABLE servicio AUTO_INCREMENT=1") or die(mysql_error());
Pon mucha atención al punto y coma ";".
no funciona y ya arregle las comas y puse el comando y no guarda nada en view.php ya no me da el error si no que pasa como en index.php que el boton no hace nada...
Cita de: shitoman en 30 Julio 2014, 04:25 AM
no funciona y ya arregle las comas y puse el comando y no guarda nada en view.php ya no me da el error si no que pasa como en index.php que el boton no hace nada...
¿Puedes poner el código final que tienes?
¿Estás revisando por algún cambio en la base de datos?
este es el codigo final del index2
<!DOCTYPE html>
<div id="content" class="style3" style="height: 5600px; width: 2600px;">
<form method="post" style="height: 442px; width: 610px">
<span class="style4">
<img alt="" class="style5" height="135" src="img/login_logo.png" style="float: left" width="156" /></span><strong> <br>
<br><br><br><br><br><br> AGREGAR GASTO<br> </strong>
<br>
<table class="style6" style="height: 253; width: 512">
<tr>
<td class="style8">Vendedor</td>
<td><input type="text" name="Vendedor" /></td>
</tr>
<tr>
<td class="style8">Semana
</td>
<td><input type="text" name="Semana" /></td>
</tr>
<tr>
<td class="style8">Quien Pago</td>
<td><input type="text" name="QuienPago" /></td>
</tr>
<tr>
<td style="height: 46px" class="style8">Proveedor</td>
<td style="height: 46px"><input type="text" name="Proveedor" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Fecha</td>
<td style="height: 65px" class="style7">
<input type="text" name="Fecha" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Nº
de Control</td>
<td style="height: 65px" class="style7">
<input type="text" name="Control" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Adelanto en la Semana</td>
<td style="height: 65px" class="style7">
<input type="text" name="Adelanto" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Cotización
</td>
<td style="height: 65px" class="style7">
<input type="text" name="Cotizacion" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Año </td>
<td style="height: 65px" class="style7">
<input type="text" name="Año" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Tipo </td>
<td style="height: 65px" class="style7">
<input type="text" name="Tipo" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Cliente </td>
<td style="height: 65px" class="style7">
<input type="text" name="Cliente" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Descripción </td>
<td style="height: 65px" class="style7">
<input type="text" name="Descripcion" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Nº Factura</td>
<td style="height: 65px" class="style7">
<input type="text" name="Factura" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Monto Total</td>
<td style="height: 65px" class="style7">
<input type="text" name="MontoTotal" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Monto Total a Pagar</td>
<td style="height: 65px" class="style7">
<input type="text" name="MontoTotal2" /></td>
</tr>
<tr>
<td style="height: 65px" class="style8">Número de Factura en Venta</td>
<td style="height: 65px" class="style7">
<input type="text" name="Factura2" /></td>
</tr>
<tr>
<td style="height: 65px"> </td>
<td style="height: 65px" class="style7"><a href="index1.php">
<input name="Button1" style="width: 147px; height: 34px" type="button" value="Regresar" class="boton"></a>
<input type="submit" name="submit" value="Agregar" style="width: 147px; height: 34px" class="boton" /></td>
</tr>
</table>
<table border="1" style="height: 31px;width: 501px;" class="style7" align="center">
<?php
if (isset($_POST['submit']))
{
include 'db.php';
$Vendedor=$_POST['Vendedor'] ;
$Semana= $_POST['Semana'] ;
$QuienPago=$_POST['QuienPago'] ;
$Proveedor=$_POST['Proveedor'] ;
$Fecha=$_POST['Fecha'] ;
$Control=$_POST['Control'] ;
$Adelanto=$_POST['Adelanto'] ;
$Cotizacion=$_POST['Cotizacion'] ;
$Año=$_POST['Año'] ;
$Tipo=$_POST['Tipo'] ;
$Cliente=$_POST['Cliente'] ;
$Descripcion=$_POST['Descripcion'] ;
$Factura=$_POST['Factura'] ;
$MontoTotal=$_POST['MontoTotal'] ;
$MontoTotal2=$_POST['MontoTotal2'] ;
$Factura2=$_POST['Factura2'] ;
mysql_query("ALTER TABLE servicio AUTO_INCREMENT=1");
mysql_query("INSERT INTO `servicio`(Vendedor,Semana,QuienPago,Proveedor,Fecha,Control,Adelanto,Cotizacion,Año,Tipo,Cliente,Descripcion,Factura,MontoTotal,MontoTotal2,Factura2)
VALUES ('$Vendedor','$Semana','$QuienPago','$Proveedor''$Fecha','$Control','$Adelanto','$Cotizacion','$Año','$Tipo','$Cliente','$Descripcion','$Factura','$MontoTotal','$MontoTotal2','$Factura2')");
}
?>
<?php
include("db.php");
$result=mysql_query("SELECT * FROM servicio");
while($test = mysql_fetch_array($result))
{
$id = $test['id'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['id']."</font></td>";
echo"<td><font color='black'>" .$test['Vendedor']."</font></td>";
echo"<td><font color='black'>". $test['Semana']. "</font></td>";
echo"<td><font color='black'>". $test['QuienPago']. "</font></td>";
echo"<td><font color='black'>". $test['Proveedor']. "</font></td>";
echo"<td><font color='black'>" .$test['Fecha']."</font></td>";
echo"<td><font color='black'>" .$test['Control']."</font></td>";
echo"<td><font color='black'>". $test['Adelanto']. "</font></td>";
echo"<td><font color='black'>". $test['Cotizacion']. "</font></td>";
echo"<td><font color='black'>". $test['Año']. "</font></td>";
echo"<td><font color='black'>" .$test['Tipo']."</font></td>";
echo"<td><font color='black'>" .$test['Cliente']."</font></td>";
echo"<td><font color='black'>". $test['Descripcion']. "</font></td>";
echo"<td><font color='black'>". $test['Factura']. "</font></td>";
echo"<td><font color='black'>". $test['MontoTotal']. "</font></td>";
echo"<td><font color='black'>". $test['MontoTotal2']. "</font></td>";
echo"<td><font color='black'>". $test['Factura2']. "</font></td>";
echo"<td> <a href ='view.php?id=$id'><strong>Editar</strong></a>";
echo"<td> <a href ='del.php?id=$id'><strong>Eliminar<strong></a>";
echo "</tr>";
}
mysql_close($conn);
?>
</table>
mysql_query("INSERT INTO `servicio`(Vendedor,Semana,QuienPago,Proveedor,Fecha,Control,Adelanto,Cotizacion,Año,Tipo,Cliente,Descripcion,Factura,MontoTotal,MontoTotal2,Factura2)
VALUES ('$Vendedor','$Semana','$QuienPago','$Proveedor''$Fecha','$Control','$Adelanto','$Cotizacion','$Año','$Tipo','$Cliente','$Descripcion','$Factura','$MontoTotal','$MontoTotal2','$Factura2')");
amigo me manda error `servicio` quitales las comillas que apartes creo que estan mal
El botón submit dices que no hace nada ¿Verdad? ¿No hace submit a la form, es lo que quieres decir?
<form method="post" style="height: 442px; width: 610px">
Ponle un action:
<form method="post" action="index.php" style="height: 442px; width: 610px">
sigue sin servir cuando me refiero a que no hace nada es que el programa cuando le doy al boton agregar me regresa al TOP osea al principio de la pagina y no me agrega nada a la base de datos
amigo leete esto se que es un poco lago el tema pero hay te explicara todo
http://foro.elhacker.net/php/duda_sobre_guardar_datos_en_cada_usuario_en_php-t418008.0.html
Cita de: ::: Devil ::: en 30 Julio 2014, 15:44 PM
amigo leete esto se que es un poco lago el tema pero hay te explicara todo
http://foro.elhacker.net/php/duda_sobre_guardar_datos_en_cada_usuario_en_php-t418008.0.html
gracias pero no me sirve, ya que mi codigo es otro...
chanfles la programacion puede ser distinta pero la metodologia es la misma
te lo pongo para que te des cuenta del insert into y del update que hay es donde te puede marcar el error
y se supone que la programacion va a ser distinta ya que no estamos haciendo el mismo proyecto hahahaha ;D
No se que haya en el db.php pero quiero creer que funciona bien para imprimir la tabla de servicio.
No te despliega nada porque no hay nada para mostrar a la hora de hacer el submit. Por lo menos ahora, si entra al submit te debería arrojar un mensaje.
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
$debug = true;
include("db.php");
if (isset($_POST['submit'])) {
if ($debug) {
echo "SUBMIT SUCCESS";
}
$Vendedor = $_POST['Vendedor'];
$Semana = $_POST['Semana'];
$QuienPago = $_POST['QuienPago'];
$Proveedor = $_POST['Proveedor'];
$Fecha = $_POST['Fecha'];
$Control = $_POST['Control'];
$Adelanto = $_POST['Adelanto'];
$Cotizacion = $_POST['Cotizacion'];
$Año = $_POST['Año'];
$Tipo = $_POST['Tipo'];
$Cliente = $_POST['Cliente'];
$Descripcion = $_POST['Descripcion'];
$Factura = $_POST['Factura'];
$MontoTotal = $_POST['MontoTotal'];
$MontoTotal2 = $_POST['MontoTotal2'];
$Factura2 = $_POST['Factura2'];
mysql_query("ALTER TABLE servicio AUTO_INCREMENT=1") or die(mysql_error());
mysql_query("INSERT INTO `servicio`(Vendedor,Semana,QuienPago,Proveedor,Fecha,Control,Adelanto,Cotizacion,Año,Tipo,Cliente,Descripcion,Factura,MontoTotal,MontoTotal2,Factura2)" .
" VALUES('$Vendedor','$Semana','$QuienPago','$Proveedor''$Fecha','$Control','$Adelanto','$Cotizacion','$Año','$Tipo','$Cliente','$Descripcion','$Factura','$MontoTotal','$MontoTotal2','$Factura2')") or die(mysql_error());
}
$result = mysql_query("SELECT * FROM servicio");
while ($test = mysql_fetch_array($result)) {
$id = $test['id'];
echo "<tr align='center'>";
echo "<td><font color='black'>" . $test['id'] . "</font></td>";
echo "<td><font color='black'>" . $test['Vendedor'] . "</font></td>";
echo "<td><font color='black'>" . $test['Semana'] . "</font></td>";
echo "<td><font color='black'>" . $test['QuienPago'] . "</font></td>";
echo "<td><font color='black'>" . $test['Proveedor'] . "</font></td>";
echo "<td><font color='black'>" . $test['Fecha'] . "</font></td>";
echo "<td><font color='black'>" . $test['Control'] . "</font></td>";
echo "<td><font color='black'>" . $test['Adelanto'] . "</font></td>";
echo "<td><font color='black'>" . $test['Cotizacion'] . "</font></td>";
echo "<td><font color='black'>" . $test['Año'] . "</font></td>";
echo "<td><font color='black'>" . $test['Tipo'] . "</font></td>";
echo "<td><font color='black'>" . $test['Cliente'] . "</font></td>";
echo "<td><font color='black'>" . $test['Descripcion'] . "</font></td>";
echo "<td><font color='black'>" . $test['Factura'] . "</font></td>";
echo "<td><font color='black'>" . $test['MontoTotal'] . "</font></td>";
echo "<td><font color='black'>" . $test['MontoTotal2'] . "</font></td>";
echo "<td><font color='black'>" . $test['Factura2'] . "</font></td>";
echo "<td> <a href ='view.php?id=$id'><strong>Editar</strong></a>";
echo "<td> <a href ='del.php?id=$id'><strong>Eliminar<strong></a>";
echo "</tr>";
}
mysql_close($conn);
?>
ya sirvio gracias amigo