PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
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
[syntax="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...[/syntax]
# 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);
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
The submitted data will be in $_GET['mlsnumber'] .. If you understand how to construct strings, then you may use that to build your query to the database.
I previously did this using coldfusion w/ a sql query.
I just added a WHERE clause to the sql that compared the two.
----------------------
<cfquery datasource="homep_props" name="checkForMatching">
SELECT *
FROM props
WHERE props.MLSnumber='#FORM.MLSnumber#'
ORDER BY props.MLSnumber</cfquery>
--------------------------
props.mlsnumber being the database field for mlsnumber, and FORM.mlsnumber being the form input by user.
Yes, PHP can do what you are asking. dull1554's example seems like it is using register_globals, so I would stear you from that first of all. You want to grab the data from the form using the $_GET array (since you are using 'get' as your form method). Then I would say to read that $_GET var into the string var that dull1554 posted and you should be golden.
<?php
$mlsnumber = $_GET['mlsnumber']; // mlsnumber in the $_GET array is the field name from the form
// Spend some time here checking and validating your form data
//Run the query
$sql = "SELECT *
FROM props
WHERE props.MLSnumber = '$mlsnumber'
ORDER BY props.MLSnumber";
//Finish up with your appropriate db functions for processing the query and fetching results
?>
# 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)
adult.swim, please use the syntax highlighting controls our forum provides. If you don't know how, read the thread linked from your first post in the thread that were inserted by us.
$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?
First suggestion: try it. Then tell us what happened.
ok i just read the guide link that Feyd gave me for posting questions. I guess I really didn't give my question much thought, I'm going to rework it and then come back and ask a more intelligent and precise question. Thank for the help so far though.