Dear Guys,

I have a problem to share with you I am now Created an Online Inquiry System but my problem is in Registratio.php Here is my code:


<?php

if (isset($_REQUEST[['Submit'])) {

$conn=mysql_connect("192.168.1.139","jarlo","mastermind") or die("Unable to Connect to Server");
$db=mysql_select_db("WMQ_GL",$conn) or die("Could not Connect to the server");

$idno = $_GET['ID_No'];
$user = $_POST['User'];
$dept = $_POST['Dept_No'];
$fname=$_POST['First_Name'];
$lname=$_POST['Last_Name'];
$mname = $_POST['Middle_Name'];
$pstreet = $_POST['Pre_Street'];
$pnumber2 = $_POST['Pre_BRGY_Id'];
$pstreet1 = $_POST['Per_Street'];
$pbnumber1 = $_POST['Per_BRGY'];
$gender = $_POST['Gender'];
$birthday= $_POST['Birth_Date'];
$pbirth= $_POST['Place_Birth'];
$nation = $_POST['Nationality'];
$email = $_POST['E_Mail'];
$telnumber = $_POST['Tel_No'];
$sdate = $_POST['Start_Date'];
$issname = $_POST['Issuer_Name'];
$type=$_POST['Type'];
$expiration=$_POST['Expiration'];
$number=$_POST['Number'];

$query = mysql_query("INSERT into IR_Customer_Tmp (ID_No,User,Dept_No, First_Name,Last_Name, Middle_Name, Pre_Street, Pre_BRGY_Id, Per_Street, Per_BRGY_Id, Gender, Birth_Date, Place_Birth, Nationality, E_Mail, Tel_No,Start_Date,Issuer_Date,Type,Expiration,Number)
					VALUES('$idno', '$user', '$dept', '$fname', '$lname', '$mname', '$pstreet', '$pnumber2', '$pstreet1', '$pbnumber1', '$gender', '$birthday', '$pbirth', '$nation', '$email', '$telnumber','$sdate','$issname','$type','$expiration','$number')");

if ($query) {		
	session_start();
	$_SESSION['$idno'] = $_POST['$idno'];                                  
header ('Location: registersuccess.php'); } else { echo ('Failed to Input Data'); } } ?>

i want my code to auto_increment value to know everytime a person want to register in the website.

    auto_increment is not something which must be implemented in php, in fact it is much easier to implement it in mysql. Just go to into phpMyAdmin and make the ID column be auto_increment (and having it as a primary key as well is a good idea). Then, when you enter data into mysql through SQL just don't specify your ID column at all. If you want to get the created auto_increment value just use the mysql_insert_id() function.

      Thanks scross but my point is:

      Example:
      if a person will register automatically the id no number will come up that id number is the person id number will be assign for here how i will do that to execute in mysql to php code.

      Thanks.

        I'm sorry but I don't really understand you 🙂 If you're trying to get the id after you have run your INSERT query then, as I said, just use the mysql_insert_id() which will return the id generated by mysql.

          Thanks Blackhorse great answer came in my mind...

            Having read that blog thread, all I can do is to post the comment I made there:

            Clever non-solution to what should be a non-problem. Autoinc primary keys should be for internal db use only and have no meaning outside the database: that is a basic principle of db design theory.

            Now neither transaction nor table locks are going to stop SHOW TABLE STATUS, indeed that is the prescribed method for examining table lock status. So any number of concurrent users are going to see the same autoinc value. Of course only one will be able to use it correctly, all others will then end up with the wrong value.

            The only method to use is that described in the MySQL documentation: do your insert then query for last_insert_id. This is not the documented method for no reason, it is because it is the one that will work.

            What continually amazes me is why so many of you continue to try to find a way around fundamental relational database behaviour. This is not peculiar to MySQL, it is normal behaviour in all the RDBMS that I know of.

            When you do want to predict and control the next id, eg for an unbroken sequence of invoice numbers, then you have to create your own process which you can use either transactions and/or table locks with. Otherwise, it is what it is so just live with it.

              In my case, I agreed with Rogers. I would upload an image to the server and put the info about that image in the database, to manage the image simply, I named the image by its id in the database. This was designed for one admin log in approach. So no concurrency issue. So I was looking for the same thing as mastermind was looking, that is I need to know the ID before it was used and found that jamie's thread.

              I already read the same comments in that thread. In the case I was working on, I already took the approach Rogers suggested. Instead of use the function there to get the id to name the image as the id. I insert the data into database first and rename the image with the id later.

              In my case, I ended up not using that function. But I think jamie's function is a smart solution, just in case masterMind may not have the alternative solutions I have and if he has no concurrency worries either.

                Thanks for the support Blackhorse, I just saw my name being trashed on Jamie's blog for pointing out the flaws in this whole idea.

                  Write a Reply...