php - Limit select options -


the other day when out friends of sudden hit me use inspect element , change name of option in select tag whatever want, stored in database (still unsure on why thinking of this, glad did!)

this select tag:

 <form name="submit" method="post" action="select.php" validate>     <select class="form-control" name="genre" id="genre" required>           <option value="" selected="selected">select genre</option>           <option value="autos , vehicles">autos , vehicles</option>           <option value="comedy">comedy</option>           <option value="education">education</option>           <option value="entertainment">entertainment</option>           <option value="film & animation">film & animation</option>           <option value="gaming">gaming</option>           <option value="howto & style">howto & style</option>           <option value="music">music</option>           <option value="news & politics">news & politics</option>           <option value="nonprofits & activism">nonprofits & activism</option>           <option value="people & blogs">people & blogs</option>           <option value="pets & animals">pets & animals</option>           <option value="science & technology">science & technology</option>           <option value="sports">sports</option>           <option value="travel & events">travel & events</option>      </select>  </form> 

i have stripped php code relevant features there:

  require ("conn/connection.php"); $conn = new pdo("mysql:host=localhost;dbname=$database", $username, $password); if(isset($_post['submit']))     {    $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);     $stmt = $conn->prepare("insert videos (genre)     values (:genre)");    $stmt->bindparam(':genre', $genre);     $genre = $_post['genre'];     $stmt->execute();         echo "done";     }     else{         echo "nope";     } 

i want options allowed stored in database , give error if "selected" invalid option. don't have of previous attempts saved woke , deleted them before slept last night, sorry. still learning php, pdo , appreciate have been scratching head hours @ this.

you keep options in own table, ids. use ids in select, , use databases foreign key management check valid entries

alternatively create array of allowed options, , check user submitted data against it:

$allowed = [     "autos , vehicles",     "comedy",     "education",     "entertainment",     "film & animation",     "gaming",     "howto & style",     ... ]; if(in_array($genre, $allowed)){     //good go }else{     //error } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -