Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/03/2006, 11:18
Avatar de zerohours
zerohours
 
Fecha de Ingreso: agosto-2004
Ubicación: San Salvador, El Salvador.
Mensajes: 60
Antigüedad: 19 años, 8 meses
Puntos: 4
Exclamación Insertado en Mysql desde PHP

Bueno este es mi primer post desde rato; estoy aprendiendo PHP y queria insertar datos en SQL bueno aca pongo los script:

prueba.sql
Código:
-- phpMyAdmin SQL Dump
-- version 2.7.0-pl2
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Mar 29, 2006 at 07:34 AM
-- Server version: 5.0.18
-- PHP Version: 5.1.2
-- 
-- Database: `x`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `prueba`
-- 

CREATE TABLE `prueba` (
  `id` int(10) NOT NULL auto_increment,
  `nombre` text character set latin1 collate latin1_spanish_ci NOT NULL,
  `apellido` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

-- 
-- Dumping data for table `prueba`
-- 

INSERT INTO `prueba` VALUES (1, 'nombre', 'apellido');
INSERT INTO `prueba` VALUES (2, '', '');
INSERT INTO `prueba` VALUES (3, 'nombre', 'apellido');
INSERT INTO `prueba` VALUES (4, '', '');
INSERT INTO `prueba` VALUES (5, '', '');
INSERT INTO `prueba` VALUES (6, '', '');
INSERT INTO `prueba` VALUES (7, '', '');
conexion.php
Código PHP:
<?php

$link
=mysql_connect("localhost""usuario""password");
mysql_select_db("base_de_datos",$link) OR DIE ("Error: Imposible Conectar");

?>
index.hmtl
Código HTML:
<html>

<head>
<meta http-equiv="Content-Language" content="es">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Pagina nueva 1</title>
</head>

<body>

<form method="POST" name="prueba" action="ingresar.php">
		<table border="0" width="100%" id="table1">
		<tr>
			<td width="67">Nombre</td>
			<td><input type="text" name="nombre" size="20"></td>
		</tr>
		<tr>
			<td width="67">Apellido</td>
			<td><input type="text" name="apellido" size="20"></td>
		</tr>
	</table>
	<p><input type="submit" value="Enviar" name="B1"><input type="reset" value="Restablecer" name="B2"></p>
</form>

</body>

</html> 
ingresar.php
Código PHP:
<? 
include("conexion.php");
mysql_query("INSERT INTO prueba (nombre,apellido) values ('$nombre','$apellido') ");
echo 
'Ingresado';
?>
ok. Bueno la cosa es que en la tabla de sql solo me va agregando archivos nulos la id se incrementa 1, 2, 3... y el nombre no, osea queda vacio y el apellido tambien; y si le cambio el valor de "$nombre" por "nombre" solo se agrega nombre y no el nombre que se coloca en el formulario.

La verdad no se mucho de esto apenas comienzo y pienso que si puedo agregar esto puedo agregar cualquier cosa espero la alluda de alguien estare muy agradecido.