1

1.Ive created a simple way to redirect users from my homepage to another page based on their selection from an auto generate input box. But there seems to be a problem with my php code as it keeps redirecting me only to the first link

2.the code for the input box on my homepage is

html
body
<form action="item-search.php">
<input class="awesomplete" name="items" onchange="this.form.submit()"   list = "mylist" placeholder = "Search Items..."/>
<datalist id = "mylist" name="items">
<option value="Item1">Item1</option>
<option value="Item2">Item2</option>
<option value="Item3">Item3</option>
</datalist>
<noscript>
<input type="submit" name="items">
<noscript/>
</form>
body
html

3.then on the item-search.php page

<?php  
$items = $_POST['items'];<br>
if ($items = 'Item1') {<br>
header("Location: item1.php");<br> 
}<br>
elseif ($items = 'Item2') {<br>
header("Location: item2.php"); <br>
}<br>
elseif ($items = 'Item3') {<br>
header("Location: item3.php"); <br>
}<br>
?>

4.but no matter what i select it redirects to item1.php

Dahlia
  • 19
  • 1
  • 8
  • 1
    In addition to kainaw's answer below, I would recommend removing `
    ` from each ling of your code. I don't think it is even syntactically correct.
    – Maximus2012 Mar 03 '16 at 15:24
  • add exit; after each header function. ex: header("Location: item1.php"); exit; – Ravinder Reddy Mar 03 '16 at 15:32
  • Im new to stack overflow so i only put the
    for display here, i didnt use
    on every line of code in my actual work.
    – Dahlia Mar 03 '16 at 15:32

1 Answers1

4

The = assigns a value. You want to use == as in

if($items == 'Item1')
kainaw
  • 4,256
  • 1
  • 18
  • 38
  • using if ($items == 'Item1') doesnt work, ive tried that already – Dahlia Mar 03 '16 at 15:40
  • That means that $items doesn't contain what you think it contains. Print $items to see what it is in it. This is called "troubleshooting." You can't troubleshoot without knowing exactly what you are working with. – kainaw Mar 03 '16 at 16:04