2013-06-24 168 views
-4

我想在用户提交表单后显示带有欢迎消息的引用标识。提交表单后显示引用ID

我的表格如下。

<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","[email protected]"); 
    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> 

现在我的问题是每当用户提交数据到MySQL,然后与身份证号码信息自动显示。所有看起来不错,但它不显示ID。

谢谢。

+0

什么呢'的print_r(mysql_insert_id());'或'的var_dump(mysql_insert_id());'说明了什么? – DanFromGermany

+0

您是否使用mysqli或PDO扩展尝试过? – DanFromGermany

+0

[**请不要在新代码中使用'mysql_ *'函数**](http://bit.ly/phpmsql)。他们不再保留[并正式弃用(https://wiki.php.net/rfc/mysql_deprecation)。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://www.brightmeup.info/article.php?a_id=2)。 – michaelb958

回答

0

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

using select max(id) from tbl; 
+0

简单的利用请。@ Hinata – user2515410

+0

实际上这个查询会给你最后的结果,用户输入你可以通过这个查询得到id –