Show URL depending on database value

0

I have the following table in my database:

I want that depending on the values of android, ios etc a different url is shown. For example if android is 1 for this user, it shows the android website.

The code I have used is the following but I am getting 'undefined index' when doing the get:

<?php

  $sql = "SELECT android, ios, macos, linux, windows FROM users";
  $result = mysqli_query($con, $sql);

  $ios = $_GET["ios"];
  $android = $_GET["android"];

  if ($ios == 1) {
    header("Location: ../consejos/ios.html");
    die();
  } elseif ($android == 1) {
    header("Location: ../consejos/ios.html");
    die();
  }
  ?>
    
asked by Alejandro 25.03.2018 в 21:06
source

1 answer

2

I think you're misusing the GET.

Your solution may be

$s = "localhost";
$bd = "nombreBD";//nombre de tu base de datos
$u = "root"; //usuario
$p = ""; //contraseña

$conexion = new mysqli($s, $u, $p, $bd);
if ($conexion->connect_errno) {
    echo "no conectado";
}
$conexion->real_query("SELECT android, ios, macos, linux, windows FROM users"); 
$resultado = $conexion->use_result();
while ($fila = $resultado->fetch_assoc()) { 
  $ios = $fila["ios"];
  $android = $fila["android"];
}


    if ($ios == 1) {
    header("Location: ../consejos/ios.html");
    exit();
  } elseif ($android == 1) {
    header("Location: ../consejos/ios.html");
    exit();
  }
    
answered by 25.03.2018 / 21:35
source