for ($i = 0; $i < count($jobs); $i++) { if (isset($_POST["job{$i}"])) { if ($isLogined === "false") { break; } $file_pointer = openFile("usr_cart/usr_{$usn}.txt", 'a+'); if (isJobExisted($file_pointer, $jobs[$i])) { print "<p>The job has already existed.</p>"; } else { $file_pointer = openFile("usr_cart/usr_{$usn}.txt", 'a+'); $line = implode("\t", $jobs[$i]); $line = "\n" . $line; writeFileAtEnd($file_pointer, $line); } $file_pointer = openFile("usr_cart/usr_{$usn}.txt", 'r'); $lines = readFileFromData($file_pointer); drawTableWithoutAdd($lines); break; } } if ($isLogined === "true") { echo "<script> document.getElementById('welcome').innerHTML = 'Welcome, {$usn}'; </script>"; } else { echo "<script> document.getElementById('welcome').innerHTML = 'You are currently a guest. Please login or register ASAP.'; </script>"; } //print("<p>No Login</p>"); ?> </tbody> </table>
</span><br><br> <br> <button type="submit" name="search" value="search" style="margin-left:372px; width:100px"> <span style="font:status-bar; font-size:20px">Search</span> </button> </div> </form> <?php if (isset($_POST["search"])) { if ($_POST["jobName"] != "" || $_POST["jobID"] != "" || $_POST["location"] != "") { /* open file to search */ $file_pointer = openFile("data.txt", "r"); /* read info */ $jobs = readFileFromData($file_pointer); /* initialize search requirements */ $jobName = $_POST["jobName"] != "" ? $_POST["jobName"] : ""; $jobID = $_POST["jobID"] != "" ? $_POST["jobID"] : ""; $location = $_POST["location"] != "" ? $_POST["location"] : ""; $jobName = htmlentities($jobName); $jobID = htmlentities($jobID); $jobID = str_pad($jobID, 6, '0', STR_PAD_LEFT); $location = htmlentities($location); if (!is_string($jobName) || !preg_match("/[0-9]*/", $jobID) || strlen($jobID) > 6 || !is_string($location)) { print "<p>Invalid input!</p>"; exit; } if ($jobName != "" && strlen($jobName) > 15) { print "<p>Invalid input!</p>"; exit;