i am using php with xampp server and i am getting the following error while i am running the program.

Unknown column 'firstname' in 'field list'

(heres the program)

CREATE DATABASE IF NOT EXISTS customerdb DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE customerdb;

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

--

-- Table structure for table customer

CREATE TABLE IF NOT EXISTS customer (
id int(11) NOT NULL,
firstname varchar(80) NOT NULL,
lastname varchar(80) NOT NULL,
email varchar(80) NOT NULL,
contact varchar(15) NOT NULL,
password varchar(80) NOT NULL,
address varchar(200) NOT NULL,
ip varchar(15) NOT NULL,
dateadded date NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

ALTER TABLE customer
MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;

Recommended Answers

All 11 Replies

Member Avatar for diafol

Show the php code you.re using to connect and the query routine

heres the php code

<?php
    define('DB_HOSTNAME', 'localhost');
    define('DB_USERNAME', 'root');
    define('DB_PASSWORD', '');
    define('DB_DATABASE', 'customerdb');
    define('DB_PORT', '3306');
    //define('DB_PREFIX', 'xyz_');

    mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD) or die(mysql_error());
    mysql_select_db(DB_DATABASE) or die(mysql_error());
Member Avatar for diafol

Ok you.re using dead code (mysql functions) consider pdo or mysqli. But that.s not the issue. Show the query with the php code that you.re running. We have no idea what you.re doing.

i am providing the entire code

<?php
    session_start();
    include 'db_connect.php';
    $_SESSION['fname'] = filter_input(INPUT_POST,'fname_fld');
    $_SESSION['lname'] = filter_input(INPUT_POST,'lname_fld');
    $_SESSION['email'] = filter_input(INPUT_POST,'em_fld');
    $_SESSION['contact'] = filter_input(INPUT_POST,'cnt_fld');
    $_SESSION['address'] = filter_input(INPUT_POST,'add_fld');

    $fname = filter_input(INPUT_POST,'fname_fld');
    $lname = filter_input(INPUT_POST,'lname_fld');
    $email = filter_input(INPUT_POST,'em_fld',FILTER_VALIDATE_EMAIL);
    $contact = filter_input(INPUT_POST,'cnt_fld');
    $pass = filter_input(INPUT_POST,'pwd_fld');
    $cpass = filter_input(INPUT_POST,'cpwd_fld');
    $address = filter_input(INPUT_POST,'add_fld');
    $ip = filter_input(INPUT_SERVER, 'SERVER_ADDR');
    $date = date('Y-m-d');

    if(null != filter_input(INPUT_POST, 'subForm')) {
        if($pass !== $cpass) {
            header('Location: signup.php?token=Password%20Mismatch');
        }
        else {
            if($fname && $lname && $email && $contact && $pass && $address) {
                mysql_query("insert into customer(firstname,lastname,email,contact,password,address,ip,dateadded) values('$fname','$lname','$email','$contact','$pass','$address','$ip','$date')") or die(mysql_error());
                unset($_SESSION['fname']);
                unset($_SESSION['lname']);
                unset($_SESSION['email']);
                unset($_SESSION['contact']);
                unset($_SESSION['address']);
                echo 'Successfully Added';

            }
        }
    }
<?php
    session_start();
    $fname = null;
    $lname = null;
    $email = null;
    $contact = null;
    $address = null;
    $token = filter_input(INPUT_GET, 'token');
    if(isset($_SESSION['fname'])) {
        $fname = $_SESSION['fname'];
    }
    if(isset($_SESSION['lname'])) {
        $lname = $_SESSION['lname'];
    }
    if(isset($_SESSION['email'])) {
        $email = $_SESSION['email'];
    }
    if(isset($_SESSION['contact'])) {
        $contact = $_SESSION['contact'];
    }
    if(isset($_SESSION['address'])) {
        $address = $_SESSION['address'];
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="charset=utf-8" />
        <link href="assets/style.css" rel="stylesheet" type="text/css"/>
        <title>Customer SignUp</title>
    </head>
    <body>
        <div id="container">
            <form id="form" name="form" method="post" action="addcustomer.php" onsubmit="return validate();">
                <header class="info">
                    <h2>SignUp Form</h2>
                </header>
                <ul>
                    <li>
                        <span style="color: red"><?php echo $token; ?></span>
                    </li>
                    <li id="fname_blk">
                        <label class="desc" for="fname_fld">First Name <span class="req">*</span></label>
                        <div>
                            <input id="fname_fld" name="fname_fld" type="text" class="text" value="<?php echo $fname; ?>" required />
                        </div>
                    </li>

                    <li id="lname_blk">
                        <label class="desc" for="lname_fld">Last Name <span class="req">*</span></label>
                        <div>
                            <input id="lname_fld" name="lname_fld" type="text" class="text" value="<?php echo $lname; ?>" required />
                        </div>
                    </li>

                    <li id="eml_blk">
                        <label class="desc" for="em_fld">Email <span class="req">*</span></label>
                        <div>
                            <input id="em_fld" name="em_fld" type="email" class="text" value="<?php echo $email; ?>" required />
                        </div>
                    </li>

                    <li id="cnt_blk">
                        <label class="desc" for="cnt_fld">Contact <span class="req">*</span></label>
                        <div>
                            <input id="cnt_fld" name="cnt_fld" type="text" title="Must be a valid Number" pattern="[0-9]{10}" value="<?php echo $contact; ?>" class="text" required />
                        </div>
                    </li>

                    <li id="pwd_blk">
                        <label class="desc" for="pwd_fld">Password <span class="req">*</span></label>
                        <div>
                            <input id="pwd_fld" name="pwd_fld" type="password" class="text" required />
                        </div>
                    </li>

                    <li id="cpwd_blk">
                        <label class="desc" for="cpwd_fld">Confirm Password <span class="req">*</span></label>
                        <div>
                            <input id="cpwd_fld" name="cpwd_fld" type="password" class="text" required />
                        </div>
                    </li>

                    <li id="add_blk">
                        <label class="desc" for="add_fld">Address <span class="req">*</span></label>
                        <div>
                            <textarea id="add_fld" name="add_fld" class="text" required /><?php echo $address; ?></textarea>
                        </div>
                    </li>

                    <li class="buttons ">
                        <div>
                            <input class="subform" id="subForm" name="subForm" type="submit" value="Submit" />
                        </div>
                    </li>
                </ul>
            </form>
        </div>
        <script src="assets/jquery.min.js"></script>
        <script src="assets/script.js"></script>
    </body>
</html>

thats the entire code i am providing anyone help me with that

Hello,
When are you getting the error about firstname not in field list? Is it when you are running the create table query or at another point in the process?
Is there already a table called customer in the customerdb database? If so is there a firstname field already defined?
If you are testing creating the database and/or table from scratch then here is a sample of the sql code I use that drops the table first then recreates it. I did not include the rest of the select since it is a long query with a couple of JOINs and UNIONs.

DROP TABLE IF EXISTS `TagLinks`;
CREATE TABLE `TagLinks` 
(
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ProductID` int(11) DEFAULT NULL,
  `TagID` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `tag` (`TagID`),
  KEY `prod` (`ProductID`)
) 
SELECT * FROM 

and now i am getting the following error when i execute the program after entering the details the error show up as following

: Make sure your input for validation

What really helps is if you put the code you are using and the error you are getting like you did initially. We can't debug your code without seeing it.

thank you for your support guys its just an class name causing the issue and it was fixed now i am done with it .

check all the file names and their extenstions to make sure that the file name matches the extensions thats the cause of the error somehow i figured it out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.