Jump to content

adult.swim

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by adult.swim

  1. I have created a html form page, and a corresponding process page. My form gets input from the user, and compares it to the fields in my database. If the input in the form matches a field in the dB, the process page returns the corresponding record. The problem is only the address input for the form works correctly. All of the other fields return all the records in the dB. I've tried varying the SQL query code many times. My question is why does only the address search work as opposed to the other input fields? search.php: form [code] <form id=\"search\" method=\"post\" action=\"process.php\"> <table class=\"search1\"> <tr> <th><label for=\"pad\">Pad Number</label></th> <td><input id=\"pad\" name=\"pad\" type=\"text\" class=\"inputbox\" size=\"50\" /><br /></td> </tr> <tr> <th><label for=\"mls\">MLS Number</label></th> <td><input id=\"mls\" name=\"mls\" type=\"text\" class=\"inputbox\" size=\"50\" /><br /></td> </tr> <tr> <th><label for=\"address1\">Address</label></th> <td><input id=\"address1\" name=\"address1\" type=\"text\" class=\"inputbox\" size=\"100\" /><br /></td> </tr> <tr> <th><label for=\"city\">City</label></th> <td><input id=\"city\" name=\"city\" type=\"text\" class=\"inputbox\" size=\"100\" /><br /></td> </tr> <tr> <th><label for=\"zip\">Zip Code</label></th> <td><input id=\"zip\" name=\"zip\" type=\"text\" class=\"inputbox\" size=\"15\" /><br /></td> </tr> </table> <br /> <table class=\"search2\"> <tr> <td> <input type=\"Submit\" value=\"Submit\" style=\"width: 60px; font-size: 1.0em; padding: 2px 10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border: solid 1px #023666; color: #ffffff; text-decoration: none;\" /> <input type=\"Reset\" value=\"Reset\" style=\"width: 60px; font-size: 1.0em; padding: 2px 10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border: solid 1px #023666; color: #ffffff; text-decoration: none;\" /> <input type=\"hidden\" name=\"op\" value=\"do\" /><p>&nbsp;</p> </td> </tr> </form> </table> [/code] --------------------------------------------- process.php: [code] <? # connect to a DSN "mydb" with a user and password "marin" $connect = odbc_connect("**", "**", "**"); # query the users table for name and surname $query = "SELECT * FROM props WHERE props.MLSnumber='$mls' OR props.Pads LIKE '%$pad%' OR props.Address LIKE '%$address1%' OR props.City='$city' OR props.Zip='$zip'"; # perform the query $result = odbc_exec($connect, $query); //output results to standard output //odbc_result_all($result, "BORDER=1"); # fetch the data from the database while(odbc_fetch_row($result)){   $mls = odbc_result($result, 2);   $address = odbc_result($result, 5);   $pad = odbc_result($result, 16);   $city = odbc_result($result, 7);   $zip = odbc_result($result, 9);   $check = odbc_result($result, 17); //  print("$mls  $address  $pad  $city  $zip");     //format results     print ("<tr>");     print ("<td>$pad</td>");     print ("<td>$mls</td>");     print ("<td>$address</td>"); print ("<td>$city</td>"); print ("<td>$zip</td>"); print ("</tr>");     } # close the connection odbc_close($connect); ?> [/code]
  2. Ive created a single input form. Its input is later compared to a column in the mysql database that Ive created (so basically its a search form). My question is how are multi input forms generally handled? My understanding is that when u query a database, u can only traverse 1 column. Is it possible to take multiple inputs and check multiple columns at the same time? Here is the code I have for my form and search pages: form.html [code]<form name="form" action="search.php" method="get">   mlsnumber:   <input type="text" name="q" />   <input type="submit" name="Submit" value="Search" /> </form>Now, enter [/code] search.php [code=php:0]  // Get the search variable from URL   $var = @$_GET['q'] ;   $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "")   {   echo "<p>Please enter a search...</p>";   exit;   } // check for a search parameter if (!isset($var))   {   echo "<p>We dont seem to have a search parameter!</p>";   exit;   } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("***", "***", "***"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("homep_listings") or die("Unable to select database"); //select which database we're using // Build SQL Query  $query = "select * from listings where mlsnumber like '%$trimmed%'    order by mlsnumber"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0)   {   echo "<h4>Results</h4>";   echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>"; // google echo "<p><a href=\"http://www.google.com/search?q="   . $trimmed . "\" target=\"_blank\" title=\"Look up   " . $trimmed . " on Google\">Click here</a> to try the   search on google</p>";   } // next determine if s has been passed to script, if not use 0   if (empty($s)) {   $s=0;   } // get results   $query .= " limit $s,$limit";   $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: &quot;" . $var . "&quot;</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned   while ($row= mysql_fetch_array($result)) {   $title = $row["mlsnumber"];   echo "$count.)&nbsp;$title" ;   $count++ ;   } $currPage = (($s/$limit) + 1); //break before paging   echo "<br />";   // next we need to do the links to other results   if ($s>=1) { // bypass PREV link if s is 0   $prevs=($s-$limit);   print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;   Prev 10</a>&nbsp&nbsp;";   } // calculate number of pages needing links   $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division   if ($numrows%$limit) {   // has remainder so add one page   $pages++;   } // check to see if last page   if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {   // not last page so give NEXT link   $news=$s+$limit;   echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";   } $a = $s + ($limit) ;   if ($a > $numrows) { $a = $numrows ; }   $b = $s + 1 ;   echo "<p>Showing results $b to $a of $numrows</p>";[/code]
  3. I've just found the code I've been looking for that Uses PHP to search a MySQL database and return paged results. I've been modifying the code to fit the specifiactions that I need. My question is what is the significance of: \"%$trimmed%\" in the SQL Query. I dont know how the backslashs work, or what they mean in this context. If u know please explain, Thank You. [code=php:0] <?php   // Get the search variable from URL   $var = @$_GET['q'] ;   $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "")   {   echo "<p>Please enter a search...</p>";   exit;   } // check for a search parameter if (!isset($var))   {   echo "<p>We dont seem to have a search parameter!</p>";   exit;   } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","username","password"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("database") or die("Unable to select database"); //select which database we're using // Build SQL Query  $query = "select * from the_table where 1st_field like \"%$trimmed%\"    order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL que [/code]
  4. Would I be able to use: $fmlsnumber = $_GET['mlsnumber']; (form input mlsnumber) ------and------- # fetch the data from the database while(odbc_fetch_row($result)){ $mlsnumber = odbc_result($result, 2); (database mlsnumber; the location of it in the database) # print("$mlsnumber \n"); } to somehow compare the two?
  5. ok I made a MS Access database, that has 2 records in it. The 1st field of the records is the ID number, the next field is the mlsnumber. I want to be able to compare the input from the form (form mlsnumber) to the field in my database. e.g. if they match output TRUE, if not output FALSE.
  6. Im trying to: 1. create a form page in HTML 2. create a .php page that queries an ODBC database that I have, and compares info submitted in the form to info in my database. My question is how can i make the comparison between my form and my databse. form.html--- <form action="process.php" method="get"> mlsnumber:   <input name="mlsnumber" type="text" /> <input name="" type="submit" /> </form> process.php--- "this is what i have so far... # connect to a DSN "homep_props" with a user and password "" $connect = odbc_connect("homep_props", "", ""); # query the users table for * $query = "SELECT * FROM props"; # perform the query $result = odbc_exec($connect, $query);
×
×
  • 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.