Adding User input to database
Posted: Fri Jul 18, 2008 11:48 pm
I am a new in PHP. It is a script to adding user data to the database but it is not working, no data is being stored into database as well as no error msg is being shown. I have attached the sql file also. plz help 
------------------------------------------------------------------------------
SQL
------------------------------------------------------------------------------
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 19, 2008 at 04:34 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `bluebell`
--
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE `user` (
`user_Id` int(10) NOT NULL default '0',
`user_name` varchar(250) collate latin1_general_ci NOT NULL,
`password` varchar(250) collate latin1_general_ci NOT NULL,
`prefix` char(5) collate latin1_general_ci default NULL,
`first_name` varchar(250) collate latin1_general_ci default NULL,
`last_name` varchar(250) collate latin1_general_ci default NULL,
`email` varchar(250) collate latin1_general_ci default NULL,
`address1` text collate latin1_general_ci,
`address2` text collate latin1_general_ci,
`city` varchar(250) collate latin1_general_ci default NULL,
`state` varchar(250) collate latin1_general_ci default NULL,
`code` varchar(250) collate latin1_general_ci NOT NULL,
`country` varchar(250) collate latin1_general_ci default NULL,
`phone` varchar(25) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`user_Id`),
KEY `user_name` (`user_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`user_Id`, `user_name`, `password`, `prefix`, `first_name`, `last_name`, `email`, `address1`, `address2`, `city`, `state`, `code`, `country`, `phone`) VALUES
(0, '', '', '', '', '', '', '', '', '', '', '', '', '0');
Code: Select all
<!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=iso-8859-1" />
<title>Adding data to the database</title>
</head>
<body>
<form action="bluebell.php" method="POST">
<input type='text' name='user_name'>Your User Name:
<p><input type='password' name='password'>Your Password:</p>
<p><select name='prefix'>
<option value='Mr.'>Mr</option>
<option value='Mrs.'>Mrs</option>
<option value='Dr.'>Dr</option>
</select></p>
<p><input type='text' name='first_name'>Your First Name:</p>
<p><input type='text' name='last_name'>Your Last Name:</p>
<p><input type='text' name='email'>Your Email Id:</p>
<p><input type='text' name='address1'>Your Address Line1:</p>
<p><input type='text' name='address2'>Your Address Line2:</p>
<p><input type='text' name='city'>Your City:</p>
<p><input type='text' name='state'>Your State:</p>
<p><input type='text' name='code'>Your Postal Code:</p>
<p><input type='text' name='country'>Your Country:</p>
<p><input type='text' name='phone'>Your Phone Number:</p>
<p><input type='submit' value='Submit'></p>
</form>
<?php
$database="bluebell";
$username="root";
$password="";
$connect=mysql_connect("localhost",$username,$password);
if(!$connect)
{
die("Couldn't connect:" . mysql_error());
}
$prefix=$_POST['prefix'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$state=$_POST['state'];
$code=$_POST['code'];
$country=$_POST['country'];
$phone=$_POST['phone'];
$db=mysql_select_db($database,$connect);
if(!$db)
{
die("Couldn't select database:" . mysql_error());
}
mysql_query("INSERT INTO user (user_name,password,prefix,first_name,last_name,email,address1,address2,city,state,code,country,phone) values ('$user_name','$password','$prefix','$first_name','$last_name','$email','$address1','$address2','$city','$state','$code','$country','$phone')");
mysql_close($connect);
?>
</body>
</html>
SQL
------------------------------------------------------------------------------
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 19, 2008 at 04:34 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `bluebell`
--
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE `user` (
`user_Id` int(10) NOT NULL default '0',
`user_name` varchar(250) collate latin1_general_ci NOT NULL,
`password` varchar(250) collate latin1_general_ci NOT NULL,
`prefix` char(5) collate latin1_general_ci default NULL,
`first_name` varchar(250) collate latin1_general_ci default NULL,
`last_name` varchar(250) collate latin1_general_ci default NULL,
`email` varchar(250) collate latin1_general_ci default NULL,
`address1` text collate latin1_general_ci,
`address2` text collate latin1_general_ci,
`city` varchar(250) collate latin1_general_ci default NULL,
`state` varchar(250) collate latin1_general_ci default NULL,
`code` varchar(250) collate latin1_general_ci NOT NULL,
`country` varchar(250) collate latin1_general_ci default NULL,
`phone` varchar(25) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`user_Id`),
KEY `user_name` (`user_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`user_Id`, `user_name`, `password`, `prefix`, `first_name`, `last_name`, `email`, `address1`, `address2`, `city`, `state`, `code`, `country`, `phone`) VALUES
(0, '', '', '', '', '', '', '', '', '', '', '', '', '0');