Hi I am a newbie in php programming and I am just wondering if anybody here can help me on this matter....
I am trying to create a php that has a form where user can search certain thing from a database, meaning when let say I type a certain word in textbox and the program will search the database that is connected to the program.....
This is as far as what I have done
<?
$dbc=odbc_connect("denggi","","");
if (!$dbc)
{exit("Connection Failed: ".$dbc);}
$query="SELECT * FROM msjp_sample";
$rs=odbc_exec($dbc,$query);
if(!$rs)
{exit("Error in SQL");}
echo '<h3>MS Access Powered Database</h3>';
while(odbc_fetch_row($rs))
{
$e_name=odbc_result($rs,"NAMA");
$bulan=odbc_result($rs,"BULAN");
$e_date=odbc_result($rs,"ONSET");
echo '<b>Nama:</b>'.$e_name.'<br>';
echo '<b>Bulan</b>'.$bulan.'<br /> <b>Date:</b>'.$e_date.'<br />
<hr/>';
}
odbc_close($dbc);
echo"</table>"
?>
Based on the code... I have already managed to connect the programming with the database...... I am currently need to know how can I make query with a textbox if I need to search for anything from a certain column within the table......
Need help building a query form for my php......
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Need help building a query form for my php......
Build your form with a textbox called "term", then query the database with a WHERE clause for either an exact match or wildcard match. You need to properly sanitize/escape the POST var as I don't know the rules for odbc/access.
You should start by reading up on SQL and MS Access and PHP.
-Shawn
Code: Select all
$term = $_POST['term'];
// for a partial match
$query = "SELECT * FROM msjp_sample WHERE NAMA LIKE '*$term*'";
// or for an exact match
$query = "SELECT * FROM msjp_sample WHERE NAMA = '$term'";-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Need help building a query form for my php......
thank you.... I'll try this method......