I try to make a website and I’d like to make a select tag where you can change your language. I mean there will be some options which you can change. For example the default site language is English but you’re want to change it to German, you can just select the german from the list. After that you click the SAVE button and the page will redirect you to indexgermany.html I tried to make a code but I am new in php so I don’t know how to do this. By the way here is my code:
<?php if(isset($_POST['submit'])) { if(isset($_POST['option'])) { if($_POST['option'] == Deutsch - DE) { header('Location: indexgerman.php'); } } } ?>
<form method="POST" action="changelang.php"> <select select name="languages" id="langs"> <option for="english" name="english">English - EN</option> <option for="germany" name="germany">Deutsch - DE</option> </select><br> <input type="submit" class="langsave" name="submit" value="SAVE"> </form>
Advertisement
Answer
<?php if(isset($_POST['submit'])) { $selected_lang = $_POST['languages']; if($selected_lang == "Deutsch - DE") { header('Location: indexgerman.php'); }else{ header('Location: indexenglish.php'); } } ?>
First thing is when u get the options from Select
tag, U put name associated with select
tag not with option
tag And U missed ""
while comparing to string Values(Deutsch – DE).