0

The issue I am having is that the data field (LDA) is not passing the information entered on the form into the $lda = date('Y-m-d H:i', strtotime($_POST['lda'])); When I look at the data submitted, regardless of what I submitted, I am getting a date of 1969-12-31 00:00:00.

I used $lda = date('Y-m-d H:i', strtotime($_POST['lda'])); because I was getting a date type error and relized that it must be that the date needed formated for MySQL.

I have the following very simple HTML form:

<form action="sd-drop-submit.php" method="post">
    <p>
        <label>Semester:</label>    
        <input type="radio" name="semester" value="Spring <?php echo date("Y");?>)">Spring <?php echo date("Y");?>
        <input type="radio" name="semester" value="Summer <?php echo date("Y");?>">Summer <?php echo date("Y");?>
        <input type="radio" name="semester" tooltip="Semester" value="Fall <?php echo date("Y");?>" required="yes" message="Please select the semester." tabindex="1">Fall <?php echo date("Y");?>  
    </p>

    <p>
        <label>Student First Name:</label> 

        <input type="text" name="stdfname" tooltip="Student's First Name" required="yes" message="Please enter the student's first name." tabindex="2"><br>
        <label>Student Last Name:</label> 
        <input type="text" name="stdlname" tooltip="Student's Last Name" required="yes" message="Please enter the student's last name." tabindex="3">
    </p>
    <p>
        <label>Student ID Number:</label>
        <input type="text" name="stdid" tooltip="Student ID Number" message="Please enter the student's ID number." required="yes" tabindex="4">
        <label>Program Code:</label>
        <input type="text" name="program" tooltip="Program Code" message="Please enter the student's program code." required="yes" tabindex="5">
    </p> 

    <p>
        <label>Course:</label> <input type="text" name="course" tooltip="Course" required="yes" message="Please enter the course information." tabindex="6"> (Example: ACA 111, ENG 101)

    </p>
    <p>
        <label>Section:</label> <input type="text" name="section" tooltip="Section" required="yes" message="Please enter the section information." tabindex="7"> (Example: 01, NT1)

    </p>
    <p>
        <label>Last day of Attendance:</label>
        <input type="date" name="LDA" tooltip="Last Day of Attendance" required="yes" message="Please enter the last day of attendance." validate="date" tabindex="8"> (Date Format Only - Please use the <a href="SD_NA.cfm">Never Attended</a> form if this student has never attanded.)<br>
    </p>

    <p>
        <label>Reason:</label>
        <input type="radio" name="reason" tooltip="Reason" value="Employment" required="yes" message="Please select the reason this student is being dropped." tabindex="9">Employment
        <input type="radio" name="reason" value="Excessive Absences">Excessive Absences
        <input type="radio" name="reason" value="Illness (Personal/Family)">Illness (Personal/Family)
        <input type="radio" name="reason" value="Missed Assignments">Missed Assignments
        <input type="radio" name="reason" value="Student Request">Student Request
        <input type="radio" name="reason" value="Other">Other

    </p>
    <p>
        <label>Instructor First Name:</label>
        <input type="text" name="instfname" tooltip="Instructor's First Name" required="yes" message="Please enter the instructor's first name." tabindex="10">
    </p> 
    <p>  
        <label>Instructor Last Name:</label>
        <input type="text" name="instlname" tooltip="Instructor's Last Name" required="yes" message="Please enter the instructor's last name." tabindex="11">
    </p>
    <p>
        <label>Instructor Email:</label>
        <input type="text" name="instemail" tooltip="Instructor's Email" required="yes" message="Please enter the instructor's email." tabindex="12">
    </p>
    <p>
        <label>Comments:</label><br>
        <textarea name="comments" tooltip="Comments" cols="100" rows="5" tabindex="13"></textarea></p>


        <input type="submit" name="Submit" value="Complete the request">
        <input type="reset" name="Reset" value="Reset" id="Reset">
    </p>
</form>

and I am using the following PHP to INSERT INTO my database.

 <?php       
//create connection
$con = mysql_connect("localhost", "wccappcust", "Y3!!f00tb@11") or die ('Sorry, could not connect to the directory database server' .mysql_error());
//Select database
mysql_select_db("wccapp16", $con) or die ('Sorry, could not connect to the directory database' .mysql_error()); 

$lda = date('Y-m-d H:i', strtotime($_POST['lda']));

//Insert our data
$sql="INSERT INTO sddrop (stdfname, stdlname, semester, stdid, program, course, section, lda, reason, instfname, instlname, instemail, comments)
VALUES
('$_POST[stdfname]', '$_POST[stdlname]', '$_POST[semester]', '$_POST[stdid]', '$_POST[program]', '$_POST[course]', '$_POST[section]', '$lda', '$_POST[reason]', '$_POST[instfname]', '$_POST[instlname]', '$_POST[instemail]', '$_POST[comments]')";

if (!mysql_query ($sql, $con))
{
    die ('Error: ' .mysql_error());
}
echo "<h2>Please print for your records</h2> ";
echo "<h3>Student Drop Form</h3>";

echo "Student Name: $_POST[stdfname] $_POST[stdlname]<br>\n";
echo "Student ID: $_POST[stdid]<br>\n";
echo "Program: $_POST[program]<br>\n";
echo "Semester: $_POST[semester]<br>\n";
echo "Course: $_POST[course] $_POST[section]<br>\n";
echo "Last Day Attended: $lda<br>\n";
echo "Reason:$_POST[reason]<br>\n";
echo "Comments: $_POST[comments]<br>\n";
echo "<hr>";
echo "Instructors Name: $_POST[instfname] $_POST[instlname]<br>\n";
echo "Instructors Email: $_POST[instemail]<br>\n";

mysql_close($con)     
 ?>

What am I missing?

Should I change

$lda = date('Y-m-d H:i', strtotime($_POST['lda'])); 

to be

$lda = $_POST (date('Y-m-d H:i', strtotime($_POST['lda'])));

I think I am so close. Any advice you can get is greatly appreciated.

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
C.Sargreant
  • 3
  • 1
  • 3
  • Make sure `$lda` is what you think it is. Maybe it's not a date time string. – aynber Aug 11 '16 at 13:55
  • You have multiple issues. The mysql_ has been removed from php7 http://php.net/manual/en/intro.mysql.php. You will want to change to mysqli_ if you can. You should be using prepared statements. Your susceptible sql injection. http://bobby-tables.com/ – Jason K Aug 11 '16 at 14:16

3 Answers3

1

Change:
$lda = date('Y-m-d H:i', strtotime($_POST['lda']));

Into:
$lda = date('Y-m-d H:i', strtotime($_POST['LDA']));

1

You date field name is capitalized.. so change your date field in the form to

 <input type="date" name="lda" tooltip="Last Day of Attendance" required="yes" message="Please enter the last day of attendance." validate="date" tabindex="8"> (Date Format Only - Please use the <a href="SD_NA.cfm">Never Attended</a> form if this student has never attanded.)<br>
Aamir
  • 2,173
  • 1
  • 29
  • 58
0

In form you are using name of field in capital letters as:

<input type="date" name="LDA" tooltip="Last Day of Attendance" required="yes" message="Please enter the last day of attendance." validate="date" tabindex="8"> (Date Format Only - Please use the <a href="SD_NA.cfm">Never Attended</a> form if this student has never attanded.)<br>

So instead of this:

$lda = date('Y-m-d H:i', strtotime($_POST['lda']));

Please name of field same as in form field name as:

$lda = date('Y-m-d H:i', strtotime($_POST['LDA']));

GET and POST method are case-sensitive.

Rohit Dhiman
  • 2,691
  • 18
  • 33
  • Thank you! I'm fairly new to PHP coding and did not know that _POST and _GET were case-sensitive. I made the form lower case and it is passing the information correctly. – C.Sargreant Aug 11 '16 at 17:13
  • @C.Sargreant that sounds good, please try to learn about every new thing before you use it. :) – Rohit Dhiman Aug 12 '16 at 04:37