Jump to content

Form, PHP Isset & MySQL Query Issue


BCAV_WEB

Recommended Posts

I'm having a few issues with a serach function in Internet Explorer, it works fine in firefox which is very annoying.

 

What basically is happening, is the a form is sumbitting and posting info across, but on itself and then this is transfered into a php variable which is used on the query. Default values have been assigned if the isset of the form is not true.

 

So I believe the issue is occuring on the " if(isset($_POST['submit'])) " but as stated it works perfectly fine in firefox. Any suggestions? 

 

 

<?php



				print "
						<form target='_self' method='POST'>
						<table class=''> 
							<tr> 
								<td>
									<input name='vehicle' type='text' id='search_name' size='16'>
									<input type='image' src='images/search.gif' alt='Search' name='submit' id='search' value='Search'/>
								</td>
							</tr>
							<tr>
								<td>
									<select name='filter' id='filter'>
										<option value='make' selected='selected'>Filter By</option>
										<option value='make'>Vehicle Manufacture</option>
										<option value='model'>Vehicle Model</option>
										<option value='our_price'>Price</option>
										<option value='delivery_time'>Delivery Time</option>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									<input type='radio' name='direction' value='ASC' checked/>Ascending 
									<input type='radio' name='direction' value='DESC' />Descending

								</td>
							</tr>	
		    			</form>
				      ";
				include "connections/dbconnect.php";

				if(isset($_POST['submit'])) 
				{	
					$vehicle = $_POST['vehicle'];
					$filter = $_POST['filter']; 
					$direction = $_POST['direction']; 
					//$rowsPerPage = $_POST['limit']; 
				}
				else
				{
					$filter = "make"; 
					$direction = "ASC"; 
				}  
				//$manfactures = "Ford";

				if(isset($_GET['limit'])) 
				{	
					$rowsPerPage = $_GET['limit'];;
				}
				else
				{
					// how many rows to show per page
					$rowsPerPage = 10;
				}


				// by default we show first page
				$pageNum = 1;

				// if $_GET['page'] defined, use it as page number
				if(isset($_GET['page']))
				{
					$pageNum = $_GET['page'];

				}

				// counting the offset
				$offset = ($pageNum - 1) * $rowsPerPage;


				$car_query = " SELECT * FROM cars WHERE model LIKE '%$vehicle%' OR make LIKE '%$vehicle%' OR model_details LIKE '%$vehicle%' OR search LIKE '%$vehicle%' ORDER BY $filter $direction LIMIT $offset, $rowsPerPage";						
				$car_result = mysql_query($car_query) or die ("Error in query: $car_query. ".mysql_error()); 
				setlocale(LC_MONETARY, 'en_GB');
				$fmt = '%i';

				// how many rows we have in database
				$query   = "SELECT COUNT(model) AS numrows FROM cars";
				$result  = mysql_query($query) or die('Error, query failed');
				$row     = mysql_fetch_array($result, MYSQL_ASSOC);
				$numrows = $row['numrows'];

				// how many pages we have when using paging?
				$maxPage = ceil($numrows/$rowsPerPage);

				// print the link to access each page
				$self = $_SERVER['PHP_SELF'];
				$nav  = '';

				for($page = 1; $page <= $maxPage; $page++)
				{
				   if ($page == $pageNum)
				   {
					  $nav .= " $page "; // no need to create a link to current page
				   }
				   else
				   {
					  $nav .= " <a href=\"$self?page=$page&limit=$rowsPerPage\">$page</a> ";
				   }
				}

				if ($pageNum > 1)
				{
				   $page  = $pageNum - 1;
				   $prev  = " <a href=\"$self?page=$page&limit=$rowsPerPage\">[Prev]</a> ";

				   $first = " <a href=\"$self?page=1&limit=$rowsPerPage\">[First Page]</a> ";
				}
				else
				{
				   $prev  = ' '; // we're on page one, don't print previous link
				   $first = ' '; // nor the first page link
				}

				if ($pageNum < $maxPage)
				{
				   $page = $pageNum + 1;
				   $next = " <a href=\"$self?page=$page&limit=$rowsPerPage\">[Next]</a> ";

				   $last = " <a href=\"$self?page=$maxPage&limit=$rowsPerPage\">[Last Page]</a> ";
				}
				else
				{
				   $next = ' '; // we're on the last page, don't print next link
				   $last = ' '; // nor the last page link
				}



				if (mysql_num_rows($car_result) > 0) 
				{


...... bringing back all the information from the database

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.