sager29 Posted November 25, 2007 Share Posted November 25, 2007 I've got a database search bar on my site, and when I submit a query it shows all of the rows in the table instead of what I'm searching for. Funny thing is, it works the first time I search, but if I back up a page and search again it shows everything? Any thoughts would be greatly appreciated. Here some code: $query="SELECT artist,title,edition,imagesize,medium,price,type,framed From listings Where artist LIKE '%$searchartist%'"; $result = mysql_query($query) or die ("Couldn't execute query."); echo "<h1>Search Results</h1>"; echo "<table width='966'>"; echo "<tr><td colspan='8'><hr /></td></tr>"; echo "<tr> <td width='124'><strong>Artist</strong></td> <td width='124'><strong>Title</strong></td> <td width='95'><strong>Type</strong></td> <td width='97'><strong>Edition</strong></td> <td width='19'><strong>Image Size</strong></td> <td width='92'><strong>Medium</strong></td> <td width='92'><strong>Framed</strong></td> <td width='92'><strong>Price</strong></td> </tr>"; while($row = mysql_fetch_assoc($result)) { extract($row); echo "<tr> <td width='124'>$artist</td> <td width='124'>$title</td> <td width='95'>$type</td> <td width='97'>$edition</td> <td width='19'>$imagesize</td> <td width='92'>$medium</td> <td width='92'>$framed</td> <td width='92'>$price</td> </tr>"; echo "<tr><td colspan='8'><hr /></td></tr>\n"; } echo "</table>\n"; ?> </body></html> Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 25, 2007 Share Posted November 25, 2007 variables are not stored from page to page on PHP, you have to use sessions or place the values in cookies or in db I recommend Sessions place sesssion_start() at the top of all php files on the receiving page of the query place <? session_start() if (isset($_POST['searchartist'])) { $_SESSION['searchartist'] = $_POST['searchartist'] } and back on the main page <? session_start() if (isset($_SESSION['searchartist'])) { $searchartist = $_SESSION['searchartist']; } Quote Link to comment Share on other sites More sharing options...
xyn Posted November 25, 2007 Share Posted November 25, 2007 use _GET. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.