Foros del Web » Programando para Internet » PHP »

MySql no ingresa datos

Estas en el tema de MySql no ingresa datos en el foro de PHP en Foros del Web. hola soy estudiante de desarrollo de aplicaciones web y tengo un problema, mysql no me suelta error pero los datos no los coge tampoco :S ...
  #1 (permalink)  
Antiguo 12/01/2013, 10:12
 
Fecha de Ingreso: enero-2013
Mensajes: 6
Antigüedad: 11 años, 3 meses
Puntos: 0
MySql no ingresa datos

hola soy estudiante de desarrollo de aplicaciones web y tengo un problema, mysql no me suelta error pero los datos no los coge tampoco :S

Código:
<?php session_start(); ?>
<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<html>
<?php $comercial = strtoupper($_SESSION["k_username"]); ?>
	<style>

		body {
			padding: 0;
			margin: 0;
			border: 0;
			background-color: #07291B;
			color: white;
			font-size: 18;
		}
		legend {
			font-weight: bold;
			letter-spacing: 5px;
		}
		fieldset {
			border-color: #B3D482;
			border-style: solid;
			width: 50%;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
			font-weight: bold;
		}
		input[type="text"] {
			border: none;
			background: #B3D482;
			color: black;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
		}
		textarea, select {
			border: none;
			background: #B3D482;
			color: black;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
		}
		input[type="number"] {
			border: none;
			background: #B3D482;
			color: black;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
		}
		input[type="radio"] {
			border: none;
			background: #B3D482;
			color: black;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
		}
		input[type="email"] {
			border: none;
			background: #B3D482;
			color: black;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
		}
		input[type="date"] {
			border: none;
			background: #B3D482;
			color: black;
			border-radius: 0.5em 0.5em 0.5em 0.5em;
		}
	</style>
	<head><script>
		function primera(){
			var cantidad=document.getElementById('cantidad').value;
     		var precio=document.getElementById('precio').value;
     		document.getElementById('total').value=cantidad*precio;
			
		}
	</script></head>
	<body>

		<div id="header">
		
				<center>

					<img src="logo.jpg" alt="Articulos religiosos" height="30px" width=""> <font color="red"><?php echo "$comercial"?></font> bienvenido!
				</center>
			

		</div>

		<form method="post" action="insertar.php">
			<div align="center">
				
				<fieldset>
					<legend>
						Cliente
					</legend>
					<table>
						<tr>
							<td>Cliente:</td><td>
							<input type="text" name="cliente" size="19"/>
							</td>

						</tr>

						<tr>
							<td>Domicilio:</td><td>
							<input type="text" name="domicilio" size="19"/>
							</td>
						</tr>
						
						<tr>
							<td>Responsable:</td><td>
							<input name="responsable" type="text" size="19"/>
							</td>
						</tr>
						
						<tr>
							<td>Email:</td><td>
							<input type="email" name="mail" size="19"/>
							</td>
						</tr>

						<tr>
							<td>Móvil:</td><td>
							<input type="number" name="movil" size="19"/>
							</td>
						</tr>
						
						

						<tr>
							<td>Comentarios:</td><td>							<textarea ></textarea></td>
						</tr>
					</table>

				</fieldset>

				<fieldset>
					<legend>
						Artículo
					</legend>

					<table>
						<tr>
							<td>Tipo:</td><td>
							<SELECT NAME="tipo" SIZE=1">
							<OPTION VALUE="medalla">Medalla</OPTION>
							<OPTION VALUE="medalla dos caras">Medalla dos caras</OPTION>
							<OPTION VALUE="medalla con fotos">Medalla con fotos</OPTION>
							<OPTION VALUE="llavero">LLavero</OPTION>
							<OPTION VALUE="llavero con foto">Llavero con fotos</OPTION>
							<OPTION VALUE="insignia">Insignia</OPTION>
							<OPTION VALUE="medallita">Medallita</OPTION>
							<OPTION VALUE="metopa">Metopa</OPTION>

							</SELECT>

							</td>
							</tr>

							<tr>
							<td>Concepto:</td><td>						<textarea name="concepto"></textarea></td>
							</tr>

							</table>

							<fieldset>
							<legend>
							Tamaño
							</legend>
							<table>
							<tr>
							<td>Altura:</td><td>
							<input type="number" name="altura" size="19"/>
							</td>
							</tr>

							<tr>
							<td>Anchura:</td><td>
							<input name="anchura" type="number" size="19"/>
							</td>
							</tr>

							<tr>
							<td>Profundidad:</td><td>
							<input name="profundidad" type="number" size="19"/>
							</td>
							</tr>

							
					</table>
				</fieldset>
				<table>
					<tr>
							<td>Enganche:</td><td> <SELECT NAME="enganche" SIZE=1">
								<OPTION VALUE="no">No</OPTION>
								<OPTION VALUE="arriba">Arriba</OPTION>
								<OPTION VALUE="detrás">Detrás</OPTION>

							</SELECT></td>
						</tr>
					<tr>
						<td>Terminación:</td><td> <SELECT NAME="terminacion" SIZE=1">
						<OPTION VALUE="oro">Oro</OPTION>
						<OPTION VALUE="plata">Plata</OPTION>
						<OPTION VALUE="cobre">Cobre</OPTION>
						<OPTION VALUE="plata oxidada">Plata oxidada</OPTION>
						<OPTION VALUE="plata mate">Plata mate</OPTION>
						</SELECT> </td>
						</tr>

						<tr>
						<td>Esmalte:</td><td><SELECT NAME="esmalte" SIZE=1">
						<OPTION VALUE="si">Si</OPTION>
						<OPTION VALUE="no">No</OPTION>
						</SELECT> </td>
						</tr>

						<tr>
						<td>Color esmalte:</td><td>
						<input name="color" type="text" size="19"/>
						</td>

						</tr>

						</table>
						</fieldset>

						<fieldset>
						<legend>
						Imágenes
						</legend>
						
						
						
						
						
						</fieldset>

						<fieldset>
						<legend>
						Precio
						</legend>
						<table>
							<tr>
						<td>Cantidad:</td><td>
						<input id="cantidad" type="number" name="cantidad" size="19"/>
						uds </td>
					</tr>
						<tr>
						<td>Precio:</td><td>
						<input id="precio" name="precio" type="number" size="19" onkeyup=" primera();"/>€/und </td>
					</tr>
					<tr>
					<td>Total:</td><td>
						<input id="total" name="total" type="text" size="19" />€</td>
					</tr>
					
					<td>Fecha limite:</td><td>
						<input id="limite" type="date" size="19"/></td>
					</tr>
				</table>

				</fieldset>
<input type="submit" value="enviar"/>
			</div>

		</form>
	</body>
</html>

y este el mysql

Código:
<html>

<body>

<?php

$link = mysql_connect("localhost", "root"); 

mysql_select_db("php", $link);

$sql = "INSERT INTO pedidos (cliente, responsable, mail, movil) VALUES ('$_REQUEST[cliente]', '$_REQUEST[responsable]', '$_REQUEST[mail]', '$_REQUEST[movil]')";

$result = mysql_query($sql);


echo "Gracias! Hemos recibido sus datos.\n";


?> 

</body>

</html>
  #2 (permalink)  
Antiguo 12/01/2013, 10:15
Avatar de rottenp4nx  
Fecha de Ingreso: octubre-2012
Ubicación: Santiago
Mensajes: 417
Antigüedad: 11 años, 6 meses
Puntos: 36
Respuesta: MySql no ingresa datos

Debe haber un problema con la conexión porque mysql_connect recibe 3 parametros

mysql_connect('servidor','usuario','password')

y te recomiendo que despues de cualquier funcion de mysql coloques

or die(mysql_error());

ej:

mysql_query("select * from tabla") or die(mysql_error());

mysql_connect('servidor','usuario','password') or die(mysql_error());

saludos
  #3 (permalink)  
Antiguo 12/01/2013, 10:18
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: MySql no ingresa datos

Primero a tu punto siempre en fase de desarrollo es bueno que depures tu consulta
Código PHP:
Ver original
  1. mysql_query("tu consulta") or die(mysql_error());

ahora ve un poco este tema http://www.forosdelweb.com/f18/anunc...ecada-1008145/
habla de la extensión mysql_* que ya esta declarada obsoleta.

También es bueno que busques un poco sobre seguridad e inyección SQL, recibir los datos de un formulario y pasarlos así a la consulta deja un hoyo de seguridad bien grande, además no soy muy amante de $_REQUEST por esta nota
Cita:
Iniciado por manual de php
Las variables en $_REQUEST se proporcionan al script a través de los mecanismos de entrada GET, POST, y COOKIE y por lo tanto pueden ser manipulados por el usuario remoto y no debe confiar en el contenido. La presencia y el orden de las variables listadas en este array se definen según la directiva de configuración PHP variables_order.
es preferible según entiendo que utilices $_GET o $_POST dependiendo del método por el que hayas pasado los datos, saludos
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #4 (permalink)  
Antiguo 12/01/2013, 10:21
 
Fecha de Ingreso: enero-2013
Mensajes: 6
Antigüedad: 11 años, 3 meses
Puntos: 0
Respuesta: MySql no ingresa datos

Gracias a todos, chicos!
  #5 (permalink)  
Antiguo 12/01/2013, 10:23
 
Fecha de Ingreso: enero-2013
Mensajes: 6
Antigüedad: 11 años, 3 meses
Puntos: 0
Respuesta: MySql no ingresa datos

No me ha solucionado nada, sigue sin insertar y no suelta errores estoy muy apurada, ayudadme :S
  #6 (permalink)  
Antiguo 12/01/2013, 10:38
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: MySql no ingresa datos

imprime el SQL y ejecutalo en el phpmyadmin o el cliente que estes usando para gestionar tu base de datos y ve si te inserta
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #7 (permalink)  
Antiguo 12/01/2013, 11:05
Avatar de zreep  
Fecha de Ingreso: octubre-2009
Ubicación: Argentina
Mensajes: 534
Antigüedad: 14 años, 6 meses
Puntos: 12
Respuesta: MySql no ingresa datos

Como dice carlos_belisario, hay alguna cosas que a mi entender faltan...
Trata de usar funciones como isset que determina si una variable esta definida, empty que se fija que si la variable esta vacia, en este caso $_POST...


Código PHP:

if(isset($_POST['enviar']))
{
    if(!empty(
$_POST['dato1']) && !empty($_POST['dato2']) && !empty($_POST['dato3']) && !empty($_POST['dato4']))
    {
        
$in "INSERT INTO pedidos (cliente, responsable, mail, movil) VALUES ('".$_POST['dato1']."','".$_POST['dato2']."','".$_POST['dato3']."','".$_POST['dato4']."')"
       
$res  =  mysql_query($in) or die(mysql_error());
if (
$res){
    echo 
'dato ingresado con exito';
    }
    }  
    else{
       echo 
'no se puedo insertar';
    }

algo asi, simple y con datos ya declarados. Espero te ayude
__________________
Zreep

Etiquetas: html, mysql, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:20.