•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,066 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,554 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1112 | Replies: 22
![]() |
•
•
Join Date: Jan 2008
Posts: 76
Reputation:
Rep Power: 1
Solved Threads: 1
I'm very new to php and am looking for help getting data out of my MYSQL database. I've made all my proper connections and all is running fine so far. What i want to do is have people get a result from the database based on their input...i.e., put in firstname, lastname and dob in three separate boxes and use that data as a way to query the database to see if they are in it based on those three items. I can do it with just lastname, but want all three to be true before a response is given. More or less like a lookup based on three variables. I just don't know enough to figure this one out by myself. Does anyone have a lookup script already working that i can play with, or pointers on how to make this work. I'm using php, mysql on IIS in windows. Hope this is enough info, appreciate anyones help. I figured out the "WHERE lname = "smith" to get a response but would like "WHERE lname = (what was inputed) AND fname = (what was inputed) AND dob = (what was inputed)"
Thanks
Thanks
Last edited by rickarro : Jan 11th, 2008 at 5:57 pm.
•
•
Join Date: Jul 2007
Location: Sofia, Bulgaria
Posts: 138
Reputation:
Rep Power: 2
Solved Threads: 10
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
Have 3 textboxes in your form. Call it firstname, lastname and date_of_birth. The page submits to 'somepage.php'. In somepage.php, you can access the form variables like,
Then in your query, you can use these posted form variables.
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
....
Then in your query, you can use these posted form variables.
$query="select * from users where firstname='$firstname' AND lastname='$lastname'";
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
•
•
Join Date: Jan 2008
Posts: 76
Reputation:
Rep Power: 1
Solved Threads: 1
Ok, i'm further than i was, after your post and reading up on other scripts, i came up with this. The form works great but i'm only seeing the actual script of my query when I run it. I have my form as in .php script and the rest in another .php script. Here is the form script.....
And here is my "fromform.php" script. I'm thinking I have my (")'s wrong in the $query = select *...... area somewhere. Can you see what I'm doing wrong?
Am I way off base here or just a few feet
Thanks again for all your help.
<body> <form name="form" action="fromform.php" method="post"> <p>Input First Name: <input name="fname" type="text" id="fname"> <p>Input Last Name: <input name="lname" type="text" id="lname"> <p>Input Date of Birth (i.e. yyyymmdd Like 20060923): <input name="dob" type="text" id="dob"> <p><input type="submit" name="submit" value="submit"> </form>
And here is my "fromform.php" script. I'm thinking I have my (")'s wrong in the $query = select *...... area somewhere. Can you see what I'm doing wrong?
<?
$host = "localhost";
$user = "myuser";
$pass = "mypassword";
$dbname = "voters";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
$dbname = "voters";
mysql_select_db($dbname);
$query= "select * from voters where lname=" . $_POST['lname'] . "; AND
fname="' . $_POST['fname'] . ""; AND dob=" . $_POST['dob'] . ""'";
echo $query;
$result= mysql_query($query);
$num_results = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
echo "<p>",$row['lname'], ": ",$row['fname'], ": ",$row['dob'];
}
?> Am I way off base here or just a few feet

Thanks again for all your help.
Last edited by rickarro : Jan 14th, 2008 at 3:44 pm.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
Yep. You are wrong in writing the query.
Check this. Don't you think this is much easier than using $_POST in your query ? I do it this way. I first assign the values of the $_POST['variable'] to a php variable, then use that php variable(in this case, $fname,$lname and $dob). And, you shouldn't end your query (with a semicolon) after every condition.
php Syntax (Toggle Plain Text)
<? $host = "localhost"; $user = "myuser"; $pass = "mypassword"; $dbname = "voters"; $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>"); $dbname = "voters"; mysql_select_db($dbname); $lname=$_POST['lname']; $fname=$_POST['fname']; $dob=$_POST['dob']; $query= "select * from voters where lname='$lname' AND fname='$fname' AND dob='$dob'"; echo $query; $result= mysql_query($query); $num_results = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { echo "<p>",$row['lname'], ": ",$row['fname'], ": ",$row['dob']; } ?>
Check this. Don't you think this is much easier than using $_POST in your query ? I do it this way. I first assign the values of the $_POST['variable'] to a php variable, then use that php variable(in this case, $fname,$lname and $dob). And, you shouldn't end your query (with a semicolon) after every condition.
Last edited by nav33n : Jan 14th, 2008 at 4:22 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 76
Reputation:
Rep Power: 1
Solved Threads: 1
•
•
•
•
Yep. You are wrong in writing the query.
php Syntax (Toggle Plain Text)
<? $host = "localhost"; $user = "myuser"; $pass = "mypassword"; $dbname = "voters"; $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>"); $dbname = "voters"; mysql_select_db($dbname); $lname=$_POST['lname']; $fname=$_POST['fname']; $dob=$_POST['dob']; $query= "select * from voters where lname='$lname' AND fname='$fname' AND dob='$dob'"; echo $query; $result= mysql_query($query); $num_results = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { echo "<p>",$row['lname'], ": ",$row['fname'], ": ",$row['dob']; } ?>
Check this. Don't you think this is much easier than using $_POST in your query ? I do it this way. I first assign the values of the $_POST['variable'] to a php variable, then use that php variable(in this case, $fname,$lname and $dob). And, you shouldn't end your query (with a semicolon) after every condition.
Yes that is much easier and cleaner, thanks. However, after cleaning it up as you stated, i'm still getting this error/display instead of the printed product....
select * from voters where lname='doe' AND fname='john' AND dob='20080126'
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
hmm.. Its showing the query because you are printing it (echo $query; ). I don't see anything wrong with the query or the script. The problem might be with your php configuration.
Last edited by nav33n : Jan 14th, 2008 at 11:57 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the PHP Forum
- Previous Thread: want to retreave data from tables after joining them using "join".
- Next Thread: paths to directories on local pc?



Linear Mode