I am designing a website that connects to a database. I am using wampserver to connect to the website.

In my customer add page I am trying to ask the website to generate an autonumber from the database. As my table in the database is set up as following:

  `CustomerID` int(11) NOT NULL DEFAULT '0',
  `Customer Name` varchar(50) NOT NULL,
  `Customer Address` varchar(60) NOT NULL,
  `Customer Postcode` int(6) DEFAULT NULL,
  `Customer Tel No` int(11) NOT NULL,
  `Customer Email` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`CustomerID`)

The page for adding a customer is as so:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<TITLE>Layout 1</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">

<script type="text/javascript" src="JSFunctions.js"/>

<div id="container">
	<div id="top">
    	<div id="logo">
        	<h1>Small Business Database      </h1>

<div id="navigation">
			<div id="nav">
           		  <tr><a href="index.php"><em></em> Homepage</a></tr>
					<tr><a href="Products.php"><em></em>Products</a></tr>
					<tr><a href="Orders.php"><em></em>Orders</a></tr>
					<tr><a href="Invoices.php"><em></em>Invoices</a></tr>
					<tr><a href="Suppliers.php"><em></em>Suppliers</a></tr>
			<div id="subnav">
       		  <ul class="dropdown">
                    	<a href="Customer.php">Customers</a>
        					<ul class="sub_menu">
                                <li><a href="Customer_add.php">Add</a></li>
                                 <li><a href="Customer_edit.php">Edit</a></li>
                                  <li><a href="Customer_delete.php">Delete</a></li>
                                   <li><a href="Customer_lookup.php">Lookup</a></li>
               	  <a href="Products.php">Products</a>
        					<ul class="sub_menu">
        						<li><a href="Products_add.php">Add</a></li>
                                 <li><a href="Products_edit.php">Edit</a></li>
                                  <li><a href="Products_delete.php">Delete</a></li>
                                   <li><a href="Products_lookup.php">Lookup</a></li>
               	    <a href="Invoice.php">Invoices</a>
       					  <ul class="sub_menu">
       						     <li><a href="Invoice_add.php">Add</a></li>
                                 <li><a href="Invoice_edit.php">Edit</a></li>
                                  <li><a href="Invoice_delete.php">Delete</a></li>
                                   <li><a href="Invoice_lookup.php">Lookup</a></li>

  </div><!-- close top-->
	<div id="main">
    <p> Add Customer</p>
<form name ="theForm" onSubmit="return validateFormOnSubmit(this)" method="POST" action="insertCustomer.php" >
<table width="500">
      <td width="250">Customer ID: </td>
      <td width="200"><select name="CustomerID"id="CustomerID"><?php CustomerID(); ?></select></td>
      <td width="250">Name: </td>
      <td width="200"><input name="name" size ="30" type="text" /></td>
      <td> Address: </td>
      <td><input name="address" size ="30" type="text" /></td>
      <td> Address Line 1: </td>
      <td><input name="address1" size ="30" type="text" /></td>
      <td> Address Line 2: </td>
      <td><input name="address2" size ="30" type="text" /></td>
      <td> County: </td>
      <td><select name="County"id="CountyList">
      <td> Postcode: </td>
      <td><input name="postcode" size ="30" type="text" /></td>
    <td> Telephone: </td>
      <td><input name="telephone" size ="30" type="text" /></td>
      <td> E-Mail: </td>
      <td><input name="email" size ="30"type="text" /></td>
      <td> Confirm E-Mail: </td>
      <td><input name="email2" size ="30"type="text" /></td>
<input type="submit" value="Submit" /> <input type = "reset" value= "Reset" ><br>



Just wondering if anyone could help me please?

Recommended Answers

All 3 Replies

First of all i want the pattern of ur autoincremented field to see how u want to do....
I m for now considering it comtaing only integer....then
for this u can do things in many ways...
first of all find the last data value from database and simply increment it by 1.
so query for this is....

SELECT customerID from table_name order by customerID desc limit 1
Member Avatar for diafol

btw use [ CODE ] tags!!!!!

after what i have told store the output in a variable and increment it....u will get the desired result...

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.