-4

I want to display the reference id with welcome message after a user submit the form.

My forms are given below.

<form action="add_customers.php" method="post"     onsubmit="MM_validateForm('name','','R','Telephone','','RisNum','E_mail','','RisEmail','pas    sport_no','','R','remarks','','R');return document.MM_returnValue">

   <tr>
    <td>&nbsp;</td>
    <td><label for="id"></label>
    <input name="id" id="id" type="hidden"/></td>
  </tr>
  <tr>
    <td>Name of the Applicant:</td>
    <td><label for="name"></label>
    <input type="text" name="name" id="name" /></td>
  </tr>
  <tr>
    <td>Telephone</td>
    <td><label for="Telephone"></label>
    <input type="text" name="Telephone" id="Telephone" /></td>
  </tr>

  <tr>
    <td>E-mail</td>
    <td><label for="E_mail"></label>
    <input type="text" name="E_mail" id="E_mail" /></td>
  </tr>

  <tr>
    <td>Country applying for :</td>
    <td><label for="country"></label>
      <select name="country" id="country">
<option>Afghanistan</option>
<option>Africa</option>
<option>Zimbabwe </option>
    </select></td>
  </tr>
  <tr>
    <td>Visa Categeory:</td>
    <td><label style="margin-left:0px" for="visa_categeory"></label>
       <select name="visa_categeory" id="visa_categeory" onChange="visacatOnchange();">
        <option>Visit</option>
        <option>Business</option>
        <option>Other</option>
    </select><br />
<input type="text" name="other_category" id="other_category" value=""     style="display:none;">
     <script type="text/javascript">
function visacatOnchange(){
    var visa_cat = document.getElementById('visa_categeory').value 
    if(visa_cat == "Other")
        document.getElementById("other_category").style.display="block";
    else
        document.getElementById("other_category").style.display="none";
 }
 </script>
      </td>
  </tr>
  <tr>
    <td>Passport No:</td>
    <td><input type="text" name="passport_no" id="passport_no" /></td>
  </tr>
  <tr>
   <td>Remarks:</td>
       <td><label for="remarks"></label>
        <textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td>
        </tr>
         <tr>
          <td>&nbsp;</td>
         <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
      </tr>
       </form>

add_customers.php

<?
     if( $_POST )
  {
   $con =          mysql_connect("esource","Solutions","Solutions@1");
   if (!$con)
    {
      die('Could not connect: ' . mysql_error());
  }
    mysql_select_db("Solutions", $con);
     $users_id = $_POST['id'];
   $users_name = $_POST['name'];
       $users_Telephone = $_POST['Telephone'];
  $users_E_mail = $_POST['E_mail'];
  $users_country = $_POST['country'];
  $users_visa_categeory = $_POST['visa_categeory'];
  $users_other_category = $_POST['other_category'];
   $users_passport_no = $_POST['passport_no'];
   $users_remarks = $_POST['remarks'];
  $query = "
      INSERT INTO `VKSolutions`.`customer_details` (
        `id`, 
       `name`, 
       `Telephone`, 
        `E_mail`, 
          `country`,
             `visa_categeory`, `other_category`,  `passport_no`,   `remarks`    
         )
            VALUES ('$users_id', '$users_name', '$users_Telephone',       '$users_E_mail',
          '$users_country',  '$users_visa_categeory', '$users_other_category',          '$users_passport_no', '$users_remarks'
          );";
    mysql_query($query);

    printf("<p>Your Reference id is %d\n (Please note this reference id for       future)<p>", mysql_insert_id());
           echo "<link rel='stylesheet' type='text/css'         href='add_customers.css'      />";
                 echo("<table>
 <tr>
        <td>Ref.ID</td>
       <td>Name of the Applicant</td>
         <td>Telephone</td>
       <td>Country Applying for</td>
       <td>Your Visa Category</td>
       <td>Other Category</td>
       <td>Your Passport Number</td>
         <td>Your Remark</td>
       </tr>

      </table>
    "); 

         mysql_close($con);
     }
      ?>

   <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>Welcome ! Your Submitted details.</title>
        </head>
      <body>
     <table style="
    ">
    <tr>
         <td><?php echo $_POST["name"]; ?></td>
          <td><?php echo $_POST["Telephone"]; ?> </td>
         <td><?php echo $_POST["E_mail"]; ?></td>
          <td><?php echo $_POST["country"]; ?> </td>
           <td><?php echo $_POST["visa_categeory"]; ?></td>
         <td><?php echo $_POST["other_category"]; ?> </td>
           <td><?php echo $_POST["passport_no"]; ?></td>
            <td><?php echo $_POST["remarks"]; ?> </td>
       </tr>

       </table>
     </body>
    </html>

Now my problem is whenever a user submit data into mysql then display that details with id number automatically. All are looking good but it does not display id.

Thanks.

4

1 回答 1

0

在提交按钮上,您可以选择最后一个 id 并显示它

using select max(id) from tbl;
于 2013-06-24T08:52:45.000 回答