I wrote the count code below with the aim of having it produce auto-serial numbers for my data in place of the MySQL serial number which goes once the row is deleted. But when I run it, I observed no entries where made to the MySQL table. I later changed the codes to Dreamweaver Insert Record and there I observed that the SN (Serial Number) fields needed not to be NULL.
By asking me to enter value to the SN field before posting it means this line code: "$query=......" and "$sn=......" will not generate the values expected of it.
So in principle I need help on how to generate an auto serial number from 1 to as many datas as will be created.
<?php
if(isset($_POST['submit']))
{
$query = mysql_query("SELECT COUNT(*) as counter FROM tbl_donors");
$sn = mysql_num_rows($query) + 1;
$donorname = $_POST['donorname'];
$designation = $_POST['designation'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$emailaddr = $_POST['emailaddr'];
$user_name = $_POST['user_name'];
mysql_select_db ($database_xxxxxxxxxx,$xxxxxxxxxx);
$query = ("INSERT INTO tbl_donors (donor_id, sn, donorname, designation, address , city, state, country , phone, emailaddr, user_name) VALUES ('', '$sn', '$donorname' , '$designation', '$address', '$city' , '$state', '$country', '$phone, '$emailaddr', '$user_name')");
$results = mysql_query($query,$xxxxxxxxxx) or die
("Could not execute query : $query." . mysql_error());
mysql_close();
}
?>