LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-09-2007, 03:03 PM   #1
orfiyus
Member
 
Registered: May 2006
Posts: 42

Rep: Reputation: 15
Problem with comparing user input to result of a query php


Whats good

I am working on a php program that reads in user input from 2 drop down menus and a text field. What I am trying to accomplish is have the user input the data from drop downs and the text field which may or may not correspond to a record in the database. The program is supposed to check if there is a record in the database that corresponds to the details entered in by the user and then refreshes the page and says whether or not it exists. After that it outputs onto a new line the same exact menu allowing you to change the details of the records the user is searching through. So basically all the info the user queried before remains on the page and he is allowed to compare it to the new info and it keeps going like that. Anyway I got drop down menus and the respawning(new menu lines) parts to work.

My problem concerns the input for the text field. The user has to type in a number for the text field then that number is put into a variable. The variable is then put in as part of a query to the db. What I dont understand how to do is compare the input text to the result of the query. To reiterate I am trying to check if a number the user enters exists in the database.

I am looking for any suggestions on how to do this. Here is the part of the code I am working with. The whole program is too long to post. I am working with an oracle database and I only have access to it through the php.

Thanks for reading through all of this.

Code:
echo("<td>");
echo("<input type=text name=opt_strk onBlur='submit();' >");
$strike_number = $_REQUEST['opt_strk'];

$query1 = "select strike from surfaces where strike = $strike_number and undl_indx = $undl_indx and expire_date = ".$_SESSION['opt_exd_vals'][$opt_indx]." and call_put = '".$_SESSION['opt_cp_vals'][$opt_indx]."' ";
$parsed1 = ociparse($db_conn, $query1);
$succ1 = ociexecute($parsed1);

echo("</td>");
 
Old 07-09-2007, 05:20 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by orfiyus
To reiterate I am trying to check if a number the user enters exists in the database.
I would suggest that you use the count to see if the number is on the database, such as:
Code:
SELECT count(*) FROM table WHERE number = number_entered
Also you may want to check that what has been entered in the text box is in fact a number before you progress with the database queries.
 
Old 07-10-2007, 09:05 AM   #3
orfiyus
Member
 
Registered: May 2006
Posts: 42

Original Poster
Rep: Reputation: 15
I dont understand if this statement returns the number of times the input appears or actually returns where the input appears.

For example if the user types in "42" and "42" appears twice does the statement return the number 2 signifying that it appears twice or does it return 2 rows where the "42" is located? If it returns the latter how would I compare it code wise? I am using severel functions to work with the database oci_parse and ociexecute. These also return 1 if true or 0 if false from what I understand about them. I think I should compare the user input to the actual row of the db where the number is located but I dont know how to do this.


Another way Im thinking of taking this is saying if the ociexecute returns true then the number exists. But I think this may be flawed if ociexecute returns true even if the number doesnt exist in the database. The PHP manual says this about ociexecute "Returns TRUE on success or FALSE on failure." Does that mean failure to connect to the db or failure to find anything in the db?

Any suggestions would be appreciated.


Heres a piece of code

Code:
//to create the text field.
echo("<input type=text name=opt_strk onBlur='submit();' >");
//assigns the the user input to a variable
$strike_number = $_REQUEST['opt_strk'];

//query the database with the appropriate details
$query1 = "select count(strike) from surfaces where strike = $strike_number and undl_indx = $undl_indx and expire_date = ".$_SESSION['opt_exd_vals'][$opt_indx]." and call_put = '".$_SESSION['opt_cp_vals'][$opt_indx]."' ";
$parsed1 = ociparse($db_conn, $query1);
//I think this returns 1 if it is true
$succ1 = ociexecute($parsed1);

//This is what I am trying to say.
if ($strike_number == <result of the query>)
    echo " variable strike_number exists in the db";
else
    echo " variable strike_number doesnt exist in the db";
 
Old 07-10-2007, 11:08 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
count returns the number of occurrences, so you can see if it exists on the database and then proceed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select query thru php outputs no result suchi_sood Programming 1 04-11-2006 10:21 AM
php/,mysql problem: can't query JJX Linux - General 4 01-06-2005 05:10 PM
mySQL redirecting query result to a .txt file! buttersoft Linux - Software 8 12-12-2003 03:05 AM
Mysql/PHP query problem with datetime field. Pcghost Programming 2 11-11-2003 12:24 PM
SQL query, comparing tables ngomong Programming 3 07-07-2002 07:44 PM


All times are GMT -5. The time now is 10:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration