A simple way to validate an html input form against a php array

"; ?> This array could be expanded to work with key value pairs, but for now we're just going to use a basic array. Our input box now checks against the array and determines whether the input is a viable input by matching the two together. Generally that input would then be passed on to a mySQL select statement, but in this case it's just an example of how to approach validating against an array of values. This way, we're limiting our query to be able to use just the values present in the data tables. That way hackers can't pass malicious code onto a select statement. The select statement, query and echo statement would look something like this: $selectStatement = $db->query("select * from tablename_courses where courseName='".$validated."'"); $result = $db->query($selectStatement); foreach($result as $row){ echo $row["courseName"]; echo $row["courseContent"]; }

See a simplified example here:

http://hardwiredmedia.com/php-array-validator/

Contact Me!

Your Name (required)

Your Email (required)

Your Message