0

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:

CREATE TABLE IF NOT EXISTS `customer` (
  `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`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

The page for adding a customer is as so:

<?php 
include('functions.php');
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<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">


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

</HEAD>
<body>
<div id="container">
	<div id="top">
    
    	<div id="logo">
        	<h1>&nbsp;</h1>
        	<p>&nbsp;</p>
        	<p>&nbsp;</p>
        	<p>&nbsp;</p>
       	  <p>&nbsp;</p>
        	<h1>&nbsp;</h1>
        	<h1>Small Business Database      </h1>
   	  </div>
      

          </div>
<div id="navigation">
			<div id="nav">
            <table>
            	<td>
           		  <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>
                 </td>
            </table>
			</div>
			<div id="subnav">
       		  <ul class="dropdown">
        	 		<li>
                    	<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>
                                
        					</ul>
        	 		</li>
           		<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>
        					</ul>
   			    </li>
           		  <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>

       					  </ul>
               	  </li>
			  </ul>
        	</div>        
		</div>
  </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">
<tr>
      <td width="250">Customer ID: </td>
      <td width="200"><select name="CustomerID"id="CustomerID"><?php CustomerID(); ?></select></td>
    </tr>
    <tr>
      <td width="250">Name: </td>
      <td width="200"><input name="name" size ="30" type="text" /></td>
    </tr>
    <tr>
      <td> Address: </td>
      <td><input name="address" size ="30" type="text" /></td>
    </tr>
      <tr>
      <td> Address Line 1: </td>
      <td><input name="address1" size ="30" type="text" /></td>
    </tr>
    <tr>
      <tr>
      <td> Address Line 2: </td>
      <td><input name="address2" size ="30" type="text" /></td>
    </tr>
      <tr>
      <tr>
      <td> County: </td>
      <td><select name="County"id="CountyList">
        <option>Antrim</option>
        <option>Armagh</option>
        <option>Carlow</option>
        <option>Cavan</option>
        <option>Clare</option>
        <option>Cork</option>
        <option>Derry</option>
        <option>Donegal</option>
        <option>Down</option>
        <option>Dublin</option>
        <option>Fermanagh</option>
        <option>Galway</option>
        <option>Kerry</option>
        <option>Kildare</option>
        <option>Kilkenny</option>
        <option>Laois</option>
        <option>Leitrim</option>
        <option>Limerick</option>
        <option>Longford</option>
        <option>Louth</option>
        <option>Mayo</option>
        <option>Meath</option>
        <option>Monaghan</option>
        <option>Offaly</option>
        <option>Roscommon</option>
        <option>Sligo</option>
        <option>Tipperary</option>
        <option>Tyrone</option>
        <option>Waterford</option>
        <option>Westmeath</option>
        <option>Wexford</option>
        <option>Wicklow</option>
      </select></td>
      </tr>
    <tr>
      <td> Postcode: </td>
      <td><input name="postcode" size ="30" type="text" /></td>
    </tr>
    <tr>
    <td> Telephone: </td>
      <td><input name="telephone" size ="30" type="text" /></td>
    </tr>
    <tr>
      <td> E-Mail: </td>
      <td><input name="email" size ="30"type="text" /></td>
    </tr>
    <tr>
      <td> Confirm E-Mail: </td>
      <td><input name="email2" size ="30"type="text" /></td>
    </tr>
    <tr>
      <td></td>
    </tr>
</table>
<input type="submit" value="Submit" /> <input type = "reset" value= "Reset" ><br>
</form>

	</div><!--/main-->
</div>
  
 
  
   

</main>
</body>
</html>

Just wondering if anyone could help me please?

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by tomato.pgn
0

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
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.