James,
Add some debugging output to your script. If it still doesn't work with
the suggestions provided here, then something that isn't obvious is
going on. Modify your original script as follows:
<?
print "<!--\n";
print "Script Init:\n";
print "\$Company: " . $Company . "\n";
print "\$Name: " . $Name . "\n";
print "\$query: " . $query . "\n";
if ($Company) {
print "\$Company found.\n";
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}
if ($Name ) {
print "\$Name found.\n";
$query = "SELECT *
FROM TBLWorking
WHERE Contact Like '%$Name%'
ORDER BY Contact";
}
print "After if statements: \$query is:\n" . $query . "\n";
$result = mysql_query($query);
print "Ran query '" . $query . "' and received result: " . $result . "\n";
$number = mysql_numrows($result);
print "Number of rows resulting from query: " . $number . "\n";
print " End Debugging -->\n";
for ($i=0; $i<$number; $i++) {
$CompanyName = mysql_result($result,$i,"Company");
$ContactName = mysql_result($result,$i,"Contact");
Print "Company: $CompanyName";
Print "<P>Name: $ContactName";
?>
Then, after running the script, look in the page source at the debugging
comments you've added. As I said, something that isn't obvious is going
on, such as when you don't give the mysql_query function a query, it
just runs the last query you ever ran. This probably isn't happening,
but if it did, it would be unexpected, and your code doesn't handle that
particular case. The code others have submitted does though, which is
part of the mystery. You need to look at the debugging comments when
you submit nothing, submit something just for Company, submit something
just for Name, and something for both Company and Name. Then your
script will hopefully tell you exactly what it's doing, leading you to
whatever the solution is.
James wrote:
Still not working...
Same results.. On entering the page, I get a complete list of companies...
On Sun, 29 Jun 2003 02:15:00 GMT, Jason Dumler
<du*********************@netscape.net> wrote:
If your script is running under Windows:
Try using the "trim" function on your if statements. i.e.:
if ( !trim($name) ) {
// do something here
}
Why? I've noticed this under Windows, with a Windows client and a
Windows server...there is an additional newline, or carriage
return/newline on the end of some of the posted variables. The string
"\r\n" and the string "\n" counts as true when you check it in an if
statement. Since you can use the enter key to move between fields, or
use the enter key to post a form when there's only one text field, the
enter string is tacked onto the end of your posted variable.
James wrote:
Sorry... It didn't work..
I created a copy of my page and renamed it, but I forgot to change the
Action in the Form, so I was loading the new page, and submitting the
results to the old page !!
Now I've changed the name of the page back, I load the new page and it
looks fine..
The form is submitted to the new page and I get NO results back !
Help !
Thanks
Is this of any help?
<form>
<!-- your form -->
</form>
<?php
$query = '';
if($company){
$query = 'blabla';
}
if($name){
$query = 'blahblah';
}
if($query != ''){
// generate your table
}
?>