prashantkadam9
Junior Member
Joined: Sun Oct 25, 2009 1:04 am Posts: 14
|
 Problem with Form values insertion in mysql
Dear Sir, I have problem with mysql insertion, If I click on submit button without filling any coloumn , it shows success message and if fill all coloums & submit, it shows success message but values are not inserting in table Also show how to use SESSION . thanks in advance. code is as below: create table leave_transaction( employee_id int(6), leave_type char(6), from_date date, to_date date, days double(6,2) default '0.00' not null, reason varchar(255); apply_on date, approved char(1), approved_date date );
<?php error_reporting(E_ALL & ~E_NOTICE); include("connect.php"); if(isset($_POST['apply'])) { $employee_id = mysql_escape_string($_POST['employee_id']); $leave = mysql_escape_string($_POST['leave']); $from = mysql_escape_string($_POST['from']); $to = mysql_escape_string($_POST['to']); $reason = mysql_escape_string($_POST['reason']); $contact = mysql_escape_string($_POST['contact']); $errorMessage = ""; if(!$employee_id) { $errorMessage .= "<li>You forgot to enter Employee ID!</li>"; } if(!$from) { $errorMessage .= "<li>You forgot to enter From date!</li>"; } if(!$to) { $errorMessage .= "<li>You forgot to enter to date!</li>"; } $result = mysql_query("INSERT INTO leave_transaction(employee_id, leave_type, from_date, to_date, days, reason, apply_on) VALUES ('$employee_id','$leave', '$from', '$to', '($to)-($from)', '$reason', now())", $connect); echo "<b>Thank you! News added Successfully! You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=leave_apply.php>"; }//end of if($submit). else { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head><title> Employee Leave Application </title></head> <body> <?php if(!empty($errorMessage)) { echo("<p>There was an error with your form:</p>\n"); echo("<ul>" . $errorMessage . "</ul>\n"); } ?> <form action="Leave_apply.php" method="POST" > <table border="0" width="775" align="center"><tr><td><fieldset> <table border="0" width="750" align="center" > <tr><td colspan=3 width="750"> </td></tr> <tr> <td colspan=3 width="750" bgcolor="#999999"> <p align="center"><font color="blue" style="font-size:20pt;"><b>Leave Application</b></font></p> </td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" bgcolor="white"> <p align="Left"><font color="blue" style="font-size:12pt;"><b>Employee ID</b> <input type=text name=employee_id size=15> </font></p> </td> <td colspan=2 width="500" bgcolor="white"> <p align="right"><font color="blue" style="font-size:12pt;"><b>Employee Name</b> <input type=text name=employeename size=50> </font></p> </td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td colspan=3 width="750" bgcolor="#999999"> <p align="center"><font color="blue"><span style="font-size:15pt;"><b>Please enter all Leave details</b></span></font></p> </td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" align="left"><b>Nature of Leave </b></font></td> <td width="250" align="left"> <select name="leave"> <option value="PL">PL</option> <option value="SL">SL</option> <option value="CL">CL</option> <option value="SPL">SPL</option> <option value="LOP">LOP</option> </select> </td> <td width="250" align="left">Date <input type=text name=date size=10></td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" align="left"><b>Balance Leave </b></font></td> <td width="250" align="left"><input type=text name=bal_Leave size=10></td> <td width="250"> </td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" align="left"><b>From Date</b></font></td> <td width="250" align="left"><input type=text name=from size=10></td> <td width="250" align="left">To Date <input type=text name=to size=10></td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" align="left"><b>Total Days</b></font></td> <td width="250" align="left"><input type=text name=total size=10></td> <td width="250"> </td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" align="left"><b>Reason for leave </b></td> <td colspan="2" width="500" align="left"><textarea name= reason rows="2" cols="40"></textarea></td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td width="250" align="left"><b>Contact no </b></font></td> <td width="250" align="left"><input type=text name=contact size=10></td> <td width="250"> </td> </tr> <tr><td colspan=3 width="750"> </td></tr> <tr> <td colspan=3 width="750" align="center" bgcolor="#999999"> <input type=submit name=apply value="Apply"> <input type=Reset value="Reset"></td> </tr> <tr><td colspan=3 width="750"> </td></tr> </table> </fieldset></td></tr></table> </form> <body> </html> <? }//end of else ?>
|