programmieren:html:forms
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| programmieren:html:forms [2026/08/12 16:03] – validation rules admin | programmieren:html:forms [2026/09/03 14:56] (current) – Mistakes admin | ||
|---|---|---|---|
| Line 117: | Line 117: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ==== 3rd Iteration ==== | ||
| + | |||
| + | In the 3rd Iteration I simply added saving the data put into the form to the Database: | ||
| + | |||
| + | <code php> | ||
| + | public function savePostData($post): | ||
| + | { | ||
| + | $servername = " | ||
| + | $username = " | ||
| + | $password = ""; | ||
| + | $dbname = " | ||
| + | |||
| + | $conn = new mysqli($servername, | ||
| + | |||
| + | if ($conn-> | ||
| + | die(" | ||
| + | } | ||
| + | |||
| + | $sql = " | ||
| + | |||
| + | $stmt = $conn-> | ||
| + | if ($stmt) { | ||
| + | $stmt-> | ||
| + | |||
| + | $name = $post[" | ||
| + | $email = $post[" | ||
| + | $phone = $post[" | ||
| + | $birthday = $post[" | ||
| + | $message = $post[" | ||
| + | |||
| + | $stmt-> | ||
| + | } else { | ||
| + | echo " | ||
| + | } | ||
| + | |||
| + | $stmt-> | ||
| + | $conn-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | And displaying all entries in the index as a list: | ||
| + | |||
| + | <code php> | ||
| + | public function displayAllEntries(): | ||
| + | { | ||
| + | $servername = " | ||
| + | $username = " | ||
| + | $password = ""; | ||
| + | $dbname = " | ||
| + | |||
| + | $conn = new mysqli($servername, | ||
| + | |||
| + | if ($conn-> | ||
| + | die(" | ||
| + | } | ||
| + | |||
| + | $sql = " | ||
| + | $result = $conn-> | ||
| + | |||
| + | if ($result-> | ||
| + | while($row = $result-> | ||
| + | echo 'Name: ' . htmlspecialchars($row[' | ||
| + | } | ||
| + | } else { | ||
| + | echo "0 results"; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Mistakes ==== | ||
| + | |||
| + | Code style: | ||
| + | |||
| + | * Apperantly I had too much repetitive code | ||
| + | * Making it object oriented was good | ||
| + | |||
| + | Functionality: | ||
| + | |||
| + | * Apperantly it was just barely reached, no explanation as to why. | ||
| + | * I couldve done better validation | ||
| + | * I couldve displayed multiple validation messages for all that was wrong | ||
| + | * I couldve used PHP native validation functions | ||
| + | * I couldve positioned the Form better | ||
| + | |||
| + | Presenting: | ||
| + | |||
| + | * I was unprepared | ||
| + | * I didn't answer many questions | ||
| + | * There were some incidents with the streaming so that was bad blegh | ||
programmieren/html/forms.1786543434.txt.gz · Last modified: by admin
