php - html forms: auto_increment field -
i'm making simple ticketing system. i'm starting off simple form user generate tripticket. 1 problem encountered wanted "ticket #" field have default value based on next incremented number. make more clear, example generated 1st trip ticket ("1") , submitted saved database.. when user generate tripticket, form must display "ticket #" field default value of "2".
currently have in html,
<form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>"> <table border=0 width="500" cellspacing=1 cellpadding=3 bgcolor="#353535" align="center"> <tr> <td bgcolor="#ffffff" colspan=2 align="center"> <span class="error">* required field.</span> </tr> <tr> <td bgcolor="#ffffff" width="30%">tt ref #:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="contract" size="10" maxlength="9" value="<?php echo $_session['contract']; ?>" disabled> <span class="error"><?php echo $contracterr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">date of usage:</td> <td bgcolor="#ffffff" width="70%"><input type="date" name="fname" value="<?php if(isset($_post['fname'])){echo $_post['fname'];} ?>" size="15" maxlength="20"> <span class="error">*<?php echo $fnameerr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">vehicle number:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="mname" value="<?php if(isset($_post['mname'])){echo $_post['mname'];} ?>" size="15" maxlength="20"> <span class="error">*<?php echo $mnameerr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">employee id:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="lname" value="<?php if(isset($_post['lname'])){echo $_post['lname'];} ?>" size="15" maxlength="20"> <span class="error">*<?php echo $lnameerr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">destination:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="number" value="<?php if(isset($_post['number'])){echo $_post['number'];} ?>" size="15" maxlength="20"> <span class="error"><?php echo $numbererr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">purpose:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="email" value="<?php if(isset($_post['email'])){echo $_post['email'];} ?>" size="15" maxlength="20"></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">status:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="username" value="<?php if(isset($_post['username'])){echo $_post['username'];} ?>" size="15" maxlength="20"> <span class="error">*<?php echo $usernameerr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">last update:</td> <td bgcol or="#ffffff" width="70%"><input type="text" name="password" value="<?php if(isset($_post['password'])){echo $_post['password'];} ?>" size="15" maxlength="20"> <span class="error">*<?php echo $passworderr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">created by:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="password" value="<?php if(isset($_post['password'])){echo $_post['password'];} ?>" size="15" maxlength="20"> <span class="error">*<?php echo $passworderr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">generation date:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="password" value="<?php echo date('y/m/d'); ?>" size="15" maxlength="20" disabled> <span class="error">*<?php echo $passworderr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">issued by:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="password" size="15" maxlength="20"> <span class="error">*<?php echo $passworderr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" width="30%">approved by:</td> <td bgcolor="#ffffff" width="70%"><input type="text" name="password" size="15" maxlength="20"> <span class="error">*<?php echo $passworderr;?></span></td> </tr> <tr> <td bgcolor="#ffffff" colspan=2 align="center"> <input type="submit" name="submit" value="submit"> <input type="reset" name="reset" value="clear"></td> </tr> </form> </body> </html>
please disregard form names not yet edited. if need more clarifications, i'm happy enlighten you. ideas or suggestions appreciated.
thank much!!
this bad approach. think happen if more 1 user trying create trip ticket using form. see same auto_id database. , first user submitting form actual value displayed in form.
better approach not show id @ all. let user submit form without knowing id. once form submitted, mysql associate auto id ticket. can id using mysql_insert_id , show user.
Comments
Post a Comment