This question already has an answer here:
So I'm working on a searchfunction for my webwshop and I've gotten pretty far. I've set the GET function up with the SELECT code on the search.php file. So I "pretty confidently" thought lets just quickly do the form and I'm done....
Well not so easy as it turns out. I've got this code now and I can't seem to send the data with the get. When you search something now all you get is http://buitenlandseproducten.nl/search.php?id= but nothing stored in the id.
<div class="form-group">
<span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
<div class="col-md-8">
<input id="form" name="form" type="text" placeholder="Search" class="form-control" >
</div>
<div class="col-md-12 text-center">
<?php
echo '<p>'. '<a href="search.php?id='.$_POST['form'].'">' . '<button type="submit" class="btn btn-secondary">' . 'Search' . '</button>' . '</a>' . '<br />';
?>
</div>
</div>
If someone could help me out here you'll be my hero forever! Help would be greatly appreciated!!
</div>
<form method="GET" action="search.php">
<input id="form" name="id" type="text" placeholder="Search" class="form-control" />
<input type='Submit' Value="Search!"/>
</form>
This should give you what i want.
<div class="form-group">
<span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
<div class="col-md-8">
<form method="GET" action="search.php">
<input id="form" name="id" type="text" placeholder="Search" class="form-control" />
<input type='Submit' Value="Search!"/>
</form>
</div>
<div class="col-md-12 text-center">
<?php
// I don't know why you have this echo below here, its not necessary for what you're trying
// echo '<p>'. '<a href="search.php?id='.$_POST['form'].'">' . '<button type="submit" class="btn btn-secondary">' . 'Search' . '</button>' . '</a>' . '<br />';
?>
</div>
</div>
The href element to link to the search.php and create a get field and assign a value to it from A POST field is kind of stretching it, and not a real smart way to go about doing it. Good luck to you, you'll need it :)
It appears as if your $_POST['form'] is not set. Using $_POST like that means that you're accessing a form after being on another page with a form. is that normal? It doesn't feel normal. Especially not when it's not secured with strip_tags or htmlentities. If you want help, you need to show the other form page's code because that is where the problem is.
You mixed GET and POST:
<form action="/search.php" method="get">
<div class="form-group">
<span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
<div class="col-md-8">
<input id="form" name="form" type="text" placeholder="Search" class="form-control" >
</div>
<div class="col-md-12 text-center">
<?php
// check if the parameter is set.
if (isset($_GET['form'])) {
echo '<p><a href="search.php?id='.urlencode($_GET['form']).'"><button type="submit" class="btn btn-secondary">Search</button></a><br />';
}
?>
</div>
</div>
</form>
Try this :
<form action="/search.php" method="GET">
<div class="form-group">
<span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
<div class="col-md-8">
<input id="form" name="id" type="text" placeholder="Search" class="form-control" >
</div>
<div class="col-md-12 text-center">
<?php
echo '<p>'. '<a href="search.php?id='.$GET['id'].'">' . '<button type="submit" class="btn btn-secondary">' . 'Search' . '</button>' . '</a>' . '<br />';
?>
</div>
</div>
</form>