will35010 Posted June 30, 2009 Share Posted June 30, 2009 I have two problems: 1. everytime the page is loaded it inserts an empty record even though I used an if(isset 2. the dates insert as 0000-00-00. The values being passed are from a select box so I those are right. <?php //script to take application data and add it to the database //to stop errors from displaying if(isset($_POST['lname'])) { } //assign varible names to post data $lName = $_POST['lname']; $fName = $_POST['fname']; $mName = $_POST['mname']; $social = $_POST['ss']; $email = $_POST['email']; $street = $_POST['street']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $street1 = $_POST['street1']; $city1 = $_POST['city1']; $state1 = $_POST['state1']; $zip1 = $_POST['zip1']; $homephone = $_POST['hphone']; $workphone = $_POST['wphone']; $applybef = $_POST['applybef']; $applyyes = $_POST['applyyes']; $presentlyemp = $_POST['presentlyemp']; $presempwhere = $_POST['presempwhere']; $reason = $_POST['reason']; $referal = $_POST['referal']; $desiredwork = $_POST['desiredwork']; //start date $startmm = $_POST['mm']; $startdd = $_POST['dd']; $startyy = $_POST['yy']; $salary = $_POST['salary']; //last four jobs //job 1 $cname = $_POST['cname']; $jobtitle = $_POST['jobtitle']; $jobstartmm = $_POST['jobmm']; $jobstartdd = $_POST['startdd']; $jobstartyy = $_POST['startyy']; $jobendmm = $_POST['endmm']; $jobenddd = $_POST['enddd']; $jobendyy = $_POST['endyy']; $startsal = $_POST['startsalary']; $endsal = $_POST['endsalary']; $super = $_POST['supname']; $supphone = $_POST['supphone']; $jobdesc = $_POST['jobdesc']; $jobreason = $_POST['jobreas']; //job 2 $cname1 = $_POST['cname2']; $jobtitle1 = $_POST['jobtitle2']; $jobstartmm1 = $_POST['jobmm2']; $jobstartdd1 = $_POST['startdd2']; $jobstartyy1 = $_POST['startyy2']; $jobendmm1 = $_POST['endmm2']; $jobenddd1 = $_POST['enddd2']; $jobendyy1 = $_POST['endyy2']; $startsal1 = $_POST['startsalary2']; $endsal1 = $_POST['endsalary2']; $super1 = $_POST['supname2']; $supphone1 = $_POST['supphone2']; $jobdesc1 = $_POST['jobdesc2']; $jobreason1 = $_POST['jobreas2']; //job 3 $cname2 = $_POST['cname3']; $jobtitle2 = $_POST['jobtitle3']; $jobstartmm2 = $_POST['jobmm3']; $jobstartdd2 = $_POST['startdd3']; $jobstartyy2 = $_POST['startyy3']; $jobendmm2 = $_POST['endmm3']; $jobenddd2 = $_POST['enddd3']; $jobendyy2 = $_POST['endyy3']; $startsal2 = $_POST['startsalary3']; $endsal2 = $_POST['endsalary3']; $super2 = $_POST['supname3']; $supphone2 = $_POST['supphone3']; $jobdesc2 = $_POST['jobdesc3']; $jobreason2 = $_POST['jobreas3']; //job 4 $cname3 = $_POST['cname4']; $jobtitle3 = $_POST['jobtitle4']; $jobstartmm3 = $_POST['jobmm4']; $jobstartdd3 = $_POST['startdd4']; $jobstartyy3 = $_POST['startyy4']; $jobendmm3 = $_POST['endmm4']; $jobenddd3 = $_POST['enddd4']; $jobendyy3 = $_POST['endyy4']; $startsal3 = $_POST['startsalary4']; $endsal3 = $_POST['endsalary4']; $super3 = $_POST['supname4']; $supphone3 = $_POST['supphone4']; $jobdesc3 = $_POST['jobdesc4']; $jobreason3 = $_POST['jobreas4']; //reference 1 $refname = $_POST['refname']; $refphone = $_POST['refphone']; $refrelate = $_POST['refrelat']; $refyears = $_POST['refyears']; //reference 2 $refname1 = $_POST['refname2']; $refphone1 = $_POST['refphone2']; $refrelate1 = $_POST['refrelat2']; $refyears1 = $_POST['refyears2']; //reference 3 $refname2 = $_POST['refname3']; $refphone2 = $_POST['refphone3']; $refrelate2 = $_POST['refrelat3']; $refyears2 = $_POST['refyears3']; //reference 4 $refname3 = $_POST['refname4']; $refphone3 = $_POST['refphone4']; $refrelate3 = $_POST['refrelat4']; $refyears3 = $_POST['refyears4']; //grammar school $gschool = $_POST['gschool']; $gschadd = $_POST['gschadd']; $gschcou = $_POST['gschcou']; $graduated = $_POST['gsch']; //high school $gschool1 = $_POST['gschool2']; $gschadd1 = $_POST['gschadd2']; $gschcou1 = $_POST['gschcou2']; $graduated1 = $_POST['gsch2']; //college$gschool = $_POST['gschool']; $gschool2 = $_POST['gschool3']; $gschadd2 = $_POST['gschadd3']; $gschcou2 = $_POST['gschcou3']; $graduated2 = $_POST['gsch3']; //other $gschool3 = $_POST['gschool4']; $gschadd3 = $_POST['gschadd4']; $gschcou3 = $_POST['gschcou4']; $graduated3 = $_POST['gsch4']; $activities = $_POST['activities']; $skills = $_POST['skills']; $felony = $_POST['felony']; $felonyes = $_POST['felonyes']; $signature = $_POST['signature']; $signmm = $_POST['signmm']; $signdd = $_POST['signdd']; $signyy = $_POST['signyy']; //convert all dates into MySql date format //yyyy-mm-dd //start date $startdate = "$startyy . $startmm . $startdd"; //job 1 start $job1start = "$jobstartyy . $jobstartmm . $jobstartdd"; //job 1 end $job1end = "$jobendyy . $jobendmm . $jobenddd"; //job 2 start $job2start = "$jobstartyy1 . $jobstartmm1 . $jobstartdd1"; //job 2 end $job2end = "$jobendyy1 . $jobendmm1 . $jobenddd1"; //job 3 start $job3start = "$jobstartyy2 . $jobstartmm2 . $jobstartdd2"; //job 3 end $job3end = "$jobendyy2 . $jobendmm2 . $jobenddd2"; //job 4 start $job4start = "$jobstartyy3 . $jobstartmm3 . $jobstartdd3"; //job 4 end $job4end = "$jobendyy3 . $jobendmm3 . $jobenddd3"; //sign date $signdate = "$signyy . $signmm . $signdd"; //db connection info require('opendb.php'); //Query to insert applicant data $query = "INSERT INTO applicants (lname, fname, mname, social, email, street, city, state, zip, street1, city1, state1, zip1, hphone, wphone, applybef, applyyes, presentlyemp, presempwhere, reason, referal, desiredwork, startdate, salary, cname, jobtitle, jobstart, jobend, startsal, endsal, super, supphone, jobdesc, jobreason, cname1, jobtitle1, jobstart1, jobend1, startsal1, endsal1, super1, supphone1, jobdesc1, jobreason1, cname2, jobtitle2, jobstart2, jobend2, startsal2, endsal2, super2, supphone2, jobdesc2, jobreason2, cname3, jobtitle3, jobstart3, jobend3, startsal3, endsal3, super3, supphone3, jobdesc3, jobreason3, refname, refphone, refrelate, refyears, refname1, refphone1, refrelate1, refyears1, refname2, refphone2, refrelate2, refyears2, refname3, refphone3, refrelate3, refyears3, edu, eduadd, educou, edugrad, edu1, eduadd1, educou1, edugrad1, edu2, eduadd2, educou2, edugrad2, edu3, eduadd3, educou3, edugrad3, activities, skills, felony, felonyes, signature, signdate) VALUES ('$lName', '$fName', '$mName', '$social', '$email', '$street', '$city', '$state', '$zip', '$street1', '$city1', '$state1', '$zip1', '$homephone', '$workphone', '$applybef', '$applyyes', '$presentlyemp', '$presempwhere', '$reason', '$referal', '$desiredwork', '$startdate', '$salary', '$cname', '$jobtitle', '$job1start', '$job1end', '$startsal', '$endsal', '$super', '$supphone', '$jobdesc', '$jobreason', '$cname1', '$jobtitle1', '$job2start', '$job2end', '$startsal1', '$endsal1', '$super1', '$supphone1', '$jobdesc1', '$jobreason1', '$cname2', '$jobtitle2', '$job3start', '$job3end', '$startsal2', '$endsal2', '$super2', '$supphone2', '$jobdesc2', '$jobreason2', '$cname3', '$jobtitle3', '$job4start', '$job4end', '$startsal3', '$endsal3', '$super3', '$supphone3', '$jobdesc3', '$jobreason3', '$refname', '$refphone', '$refrelate', '$refyears', '$refname1', '$refphone1', '$refrelate1', '$refyears1', '$refname2', '$refphone2', '$refrelate2', '$refyears2', '$refname3', '$refphone3', '$refrelate3', '$refyears3', '$gschool', '$gschadd', '$gschcou', '$graduated', '$gschool1', '$gschadd1', '$gschcou1', '$graduated1', '$gschool2', '$gschadd2', '$gschcou2', '$graduated2', '$gschool3', '$gschadd3', '$gschcou3', '$graduated3', '$activities', '$skills', '$felony', '$felonyes', '$signature', '$signdate')"; //send query to database mysqli_query($conn, $query) or die('Error: ' . mysql_error()); //close db conn require('closedb.php'); ?> Link to comment https://forums.phpfreaks.com/topic/164185-solved-two-should-be-simple-problems/ Share on other sites More sharing options...
will35010 Posted June 30, 2009 Author Share Posted June 30, 2009 I thought I'd attach the entire script including the html if it helps. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/164185-solved-two-should-be-simple-problems/#findComment-866082 Share on other sites More sharing options...
will35010 Posted June 30, 2009 Author Share Posted June 30, 2009 I fixed the date problem. How do I keep it from inserting an empty record when the page is loaded? Link to comment https://forums.phpfreaks.com/topic/164185-solved-two-should-be-simple-problems/#findComment-866096 Share on other sites More sharing options...
abdfahim Posted June 30, 2009 Share Posted June 30, 2009 if you end ur if statement instantly, then write other codes, what is the point of the IF statement?? just put all the codings inside IF like below if(isset($_POST['lname'])) { // ALL Your code, where you insert, should go here } Link to comment https://forums.phpfreaks.com/topic/164185-solved-two-should-be-simple-problems/#findComment-866097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.