0

if isset button

I'm trying to make the $sql variable change once the button with the name 'lang_en' is submitted, so it goes from selecting the 'eng_text' tab to select the 'it_text' tab, but it doesn't seems to work. Can you help? <?php include 'includes/conn.php'; if(isset($_POST['lang_en'])){ $sql = "SELECT * FROM it_text"; } else{ $sql = "SELECT * FROM eng_text"; } $result = mysqli_query($conn, $sql); $row = mysqli_fetch_all($result, MYSQLI_ASSOC); var_dump($sql); ?> <a href="#" type="submit" name='lang_en' class="w3-circle w3-margin w3-padding bg-img w3-display-topright" style="background-image: url('img/italian_flag.png')">IT</a> this is what's there in conn.php: <?php $serverName = 'localhost'; $userName = 'root'; $password = ''; $database = 'pers_text'; $conn = new mysqli($serverName, $userName, $password, $database)

8th May 2020, 3:49 PM
Francesco Paolini
Francesco Paolini - avatar
1 Resposta
+ 1
Actually, there is no attribute named type in the anchor tag. What's happening here is that when you click the link the page gets reloaded only. It's like hitting the refresh button of the browser. What you need to do is that create a form tag and set the method attribute to POST. Then inside the form tag create a button and set the type to submit and name to lang_en. In this case, the page will not only reload but also send the data. So there will be a key in $_POST named lang_en.
8th May 2020, 7:27 PM
Shashank Shekhar
Shashank Shekhar - avatar