Jump to content

MatthewPatten

Members
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

0 Neutral

About MatthewPatten

  • Rank
    Member
  1. MatthewPatten

    Create Table with TIMESTAMP and MYSQLI Query

    Finally got the NOW() function working!
  2. Hello everyone! I am trying to insert a student into a table (with TIMESTAMP; works with VARCHAR, not TIMESTAMP). Can anyone help? Variable $time_stamp = date("D M j G:i:s T Y"); Populate DB Query ("DROP TABLE IF EXISTS enrolled") || !$link->query("CREATE TABLE enrolled(course_id VARCHAR(50), student_id VARCHAR(50), user_ip VARCHAR(50), time_stamp TIMESTAMP(6)) Insert Query INSERT INTO enrolled(course_id,student_id,user_ip,time_stamp) VALUES('$course','$number','$user_ip','$time_stamp')
  3. MatthewPatten

    Invalid Selection

    I've been trying the methods that have been suggested, just cannot get it to work.
  4. MatthewPatten

    Invalid Selection

    I am trying to stop an invalid selection (validate selection) from happening if a user modifies the source code. However, I am unsure of how to do so. Here is my code below: <form action="index.php" method="POST"> <?php if (isset($_POST['course'])) { $course = htmlentities($course); //Prints if the student has been successfully enrolled into the course if ($success == 1) { echo '<font color="#12df12">You have successfully enrolled in ' . htmlspecialchars($course_name) . ' (' . htmlspecialchars($course) . ')!</font>'; } //Prints if the person registering has entered data incorrectly into the form if ($found == 0) { echo '<font color="#ff0000">The credentials you have entered are incorrect, please try again.</font>'; } else { //Prints if the student has already enrolled in the course if ($findregistered == 1) { $option = mysqli_query($link, "SELECT * FROM courses WHERE course_code = '$course'") or die(mysql_error()); while ($row = mysqli_fetch_assoc($option)) { foreach ($row as $key1 => $value1) { $$key1 = $value1; } echo '<font color="#ff0000">You have already enrolled in ' . htmlspecialchars($course_name) . ' (' . htmlspecialchars($course) . ')!</font>'; } } else { //Prints if the course the student has selected is full if ($number_max == 1) { echo '<font color="#ff0000">Sorry ' . htmlspecialchars($course_name) . ' (' . htmlspecialchars($course) . ') is full, please select another course.</font>'; } } } } ?> <p> <input name="name" placeholder="Student Name" type="text"> <input name="number" placeholder="Student Number" type="text"> </p> <p> <select name="course" size="1"> <option id="select">-- Select Course --</option> <?php $lf = "\n"; $ht = "\t\t"; $option = mysqli_query($link, "SELECT * FROM courses ORDER BY course_name") or die(mysql_error()); while ($row = mysqli_fetch_assoc($option)) { foreach ($row as $key1 => $value1) { $$key1 = $value1; } /** * Dynamically creates the option values for the select box based on course info from course_array * Added Currently Enrolled to the course list so the end-user would have an idea of how many were currently enrolled in the course. **/ $a = $ht . '<option value="' . $course_code . '">' . $course_name . ' (Enrolled: ' . $enrollment . ')</option>' . $lf; echo $a; } mysqli_close($link); ?> </select> </p> <p> <input type="submit" value="Send"><input type="reset" value="Clear"> </p> </form>
  5. MatthewPatten

    Invalid Selection

    Thank you!
  6. MatthewPatten

    Invalid Selection

    What would that look like?
  7. MatthewPatten

    Invalid Selection

    How can I prevent someone from making an ivalid selection in a form? Lets say I had a select dropdown box and someone saved the HTML source from the browser, changed an item in the list, and changed the action to point back to my server eg. action="testsite.com/index.php". Then they open the file and try to submit the form.
  8. MatthewPatten

    Jump Line in File

    Thank you good Sir, this has seemed to have resolved my issue.
  9. MatthewPatten

    Jump Line in File

    If I change that, I get this error
  10. MatthewPatten

    Jump Line in File

    So I'm basically done an assignment, however I'm having the biggest brainfart at the moment. For the life of me I cannot remember how to "jump line" in a file and have to put "end" at the end of my txt files. Also I have to put a break in my code which messes up my formatting: $coursedata = explode(' ', rtrim($coursedata)); $studentdata = explode(' ', rtrim($studentdata)); fwrite($fp, $number.'||'.$_POST['course'].' '.$content); Here is the main code below for the script: <html> <head> <?php $success = 0; $number_of_registered = 0; $course_array = getdatafile('courses.txt'); $registered_array = getdatafile('register.txt'); #______________global variables____________________ function getdatafile($file) { # code... $coursedata = file_get_contents($file); $coursedata = explode(' ', rtrim($coursedata)); unset($coursedata[count($coursedata) - 1]); $course_array = array(); foreach($coursedata as $row) { $course_array[] = explode('||', $row); } return $course_array; } #_____________functions_______________________ if (isset ($_POST['name']) and isset ($_POST['number']) and isset ($_POST['course'])) { #________________test if the post exists $name = $_POST['name']; $number = $_POST['number']; $found = 0; $findregistered = 0; for ($i = 0; $i < sizeof($registered_array); $i++) { if ($registered_array[$i][0] == $_POST['number'] && $registered_array[$i][1] == $_POST['course']) { # ___________test if the student is enrolled in this course $findregistered = 1; } if($registered_array[$i][1] == $_POST['course']) { #________counter of the number registered in this course $number_of_registered++; } } for ($i = 0; $i < sizeof($course_array); $i++) { if ($course_array[$i][1] == $_POST['course']) { # ______________this test if the number of registered is the max $course_name = $course_array[$i][0]; $findcourse = 1; if($number_of_registered < $course_array[$i][2]) { $number_max = 0; } else { $number_max = 1; } } } $studentdata = file_get_contents('students.txt'); $studentdata = explode(' ', rtrim($studentdata)); for ($i = 0; $i < sizeof($studentdata); $i++) { list($studentname, $studentnumber) = explode("||", rtrim($studentdata[$i])); if (strtoupper($name) == strtoupper($studentname) && strtoupper($number) == strtoupper($studentnumber)) { $found = 1; if ($findcourse == 1 && $findregistered == 0 && $number_max == 0) { # _____________________do all the tests to record the student in the course("register.txt") and do it if all the test are checked $success = 1; $content = file_get_contents('register.txt'); $fp = fopen('register.txt', 'w'); fwrite($fp, $number.'||'.$_POST['course'].' '.$content); fclose($fp); echo "<title>".strtoupper($name).",".strtoupper($studentname)."</title>"; } } } } ?> <style> body, p{padding: 0;margin: 0;} </style> </head> <body> <form action="index.php" method="POST"> <?php if (isset ($_POST['course'])) { $course = htmlentities ($_POST['course']); # ___________________print the information of rgester in the screen for if ($success == 1) { echo "You have successfully enrolled in $course_name, $course!"; } if($found == 0) { echo 'The credentials you have entered are incorrect, please try again.'; } else { if($findregistered == 1) { echo 'You have already enrolled in this course.'; } else { if($number_max == 1) { echo "Sorry $course_name, $course is full, please select another course."; } } } } ?> <p>Courses</p> <p><input name = "name" placeholder = "Student Name" type = "text"></p> <p><input name = "number" placeholder = "Student Number" type = "text"></p> <p><select name = "course" size = "1"> <option id = "select">-- Select Course --</option> <?php for ($i = 0; $i <sizeof($course_array); $i++) { $number_of_registered1 = 0; for ($j = 0; $j < sizeof($registered_array); $j++) { if($registered_array[$j][1] == $course_array[$i][1]) { $number_of_registered1++; } } $a = '<option value = "'.$course_array[$i][1].'">'.$course_array[$i][0].' registered:'.$number_of_registered1.'</option>'; echo $a; } ?> </select></p> <p><input type = "submit" value = "Send"><input type = "reset" value = "Clear"></p> </form> </body> </html> courses.txt register.txt students.txt index.php
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.