PDA

View Full Version : Database is only displaying one entry


dkco
11-24-2008, 09:51 AM
Hi all, I posted a little while ago on the General board and have made a lot of progress since then, but I'm hitting another roadblock (hopefully my last). I have a site where a student can type in their student number, click Search and be presented with their name, level number, class times, etc. I finally figured out enough phpmyadmin to put together a database and got it plugged into Dreamweaver. I think I'm set up correctly, but no matter what student number I type into the blank I'm only being presented with one record. Here's my setup (and keep in mind I have zero experience doing this):

1) My main page has a single line text field. It also has a Search button with the action 'submit form'. That's all in a red dotted-line box with the action 'getresults.php'. My method is GET (but I've tried POST, too).

2) getresults.php has a text block saying 'Student Name' and a light blue {} field next to it that says {Recordset1.name}. I don't know how to code myself, so under Bindings I put a new query called Recordset1. My connection is good, as is my table. I have columns set to just display the name (till I get my problem worked out). And then under filters, I want to display the name of a student based on what student number (snumber) they typed into the field. Here's the code if you're interested:

mysql_select_db($database_dbconfig, $dbconfig);
$query_Recordset1 = "SELECT name FROM test WHERE snumber = snumber";
$Recordset1 = mysql_query($query_Recordset1, $dbconfig) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

So for some reason it's only displaying the first name in my database, no matter what 'snumber' I enter. Any thoughts?

David

dkco
11-24-2008, 11:46 AM
This is sort of an update... When I have the Bindings dialogue open, I can select 'Test' and it displays the proper student name. However, when I actually preview the site, it is now displaying nothing. I played around with some things and realized that I have to use Form Variable in the filter because I have POST in the form method. So now I'm just trying to figure out why the test works, but the actual site doesn't.

edbr
11-25-2008, 01:05 AM
where you have snumber = snumber in your select statement what is snumber? ih it is a value from a form it would typically be $_POST['snumber']. my gus from what you hav edescribed

dkco
11-25-2008, 06:54 AM
snumber is their student number. What I want is for the server to check the number they enter against the unique student numbers (snumber) on the database and only display the results from that entry.

I'll double check what you suggested, though.

Dave

dkco
11-25-2008, 08:24 AM
Well that's weird... So under Bindings I go to my Recordset and I selected Test. It displays the record information that goes with whatever number I entered, but under 'Record' it has all my records as Record 1. Could that be the problem?

edbr
11-25-2008, 08:47 AM
snumber is the name of your database field yes? If a value is being passed from a form it will be a $_post value. if number 4 is entered in a form say fieldname snumber when submited $_POST['snumber'} will = 4

dkco
11-25-2008, 12:31 PM
Alright, I got things sorted out. I'll mention what I did in case anyone else runs up against this.

Basically under Filters I'd selected Form Variable, but instead of typing in the name of my field in the next box, I had snumber, since that is what Dreamweaver had put there by default. Essentially DW knew that it was supposed to use a form variable, but I'd never told it which one (called textfield on my site, the default name). The reason it was pulling up the first record in place of all other records was because that was the default number.

Many thanks to those who offered a helping hand, and put up with my nooby questions!

Dave