473,378 Members | 1,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Form Problem ! Please Help !

My form and results are on one page.
If I use :

if ($Company) {
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}

if ($Name ) {
$query = "SELECT *
FROM TBLWorking
WHERE Contact Like '%$Name%'
ORDER BY Contact";
}
$result = mysql_query($query);
$number = mysql_numrows($result);
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";
}

As soon as I enter the page it searchs using $Name, even though I have not
entered any information.

This results in me getting a complete list printed on screen, with out me
having to search.

How do I get this to show just the form, then the form and the results ?

Thanks

Jul 16 '05 #1
11 3971
Same result.

As soon as I enter the page, I get a full list of all companies !

On Sat, 28 Jun 2003 23:58:58 +0200, "sotto" <ju**@sotto.be> wrote:
just a quick idea...
try if($company!=''){ ... and if($name!='') { ....


Jul 16 '05 #2
On Sat, 28 Jun 2003 22:45:50 +0100, James wrote:
My form and results are on one page.
If I use :

if ($Company) {
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}
}
if ($Name ) {
$query = "SELECT *
FROM TBLWorking
WHERE Contact Like '%$Name%'
ORDER BY Contact";
}
}

$result = mysql_query($query);
$number = mysql_numrows($result);
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";
}
}
As soon as I enter the page it searchs using $Name, even though I have not
entered any information.

This results in me getting a complete list printed on screen, with out me
having to search.

How do I get this to show just the form, then the form and the results ?

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
}
?>
Jul 16 '05 #3
Thanks.

Now when I enter the page it only has the form visible.

However, If I submit the form blank, then I get a complete list of all
companies.

Can that be trapped, If $Company & $Name are blank then just display the
form ??

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
}
?>


Jul 16 '05 #4

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
}
?>


Jul 16 '05 #5
Message-ID: <cq********************************@4ax.com> from James
contained the following:
The form is submitted to the new page and I get NO results back !
Just spotted this:
From tblworking ....
FROM TBLWorking


--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 16 '05 #6
On Sat, 28 Jun 2003 23:44:02 +0100, James wrote:
Thanks.

Now when I enter the page it only has the form visible.

However, If I submit the form blank, then I get a complete list of all
companies.

Can that be trapped, If $Company & $Name are blank then just display the
form ??

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
}
?>


if you used that structure i gave you, then it should be like this:

it generates the form,
then, if $company != '' then the query will be built to get records based
on company
then if $name != '' then the query will be built to get records based
on name

then if query != '' then you're generating the table ...

so if $name & $company are both '' then $query will be '' and no table
would be generated
try again changing if($company) into if($company != '') ... just to be
sure that that's not he problem (also with $name)
Jul 16 '05 #7
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
}
?>



Jul 16 '05 #8
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
}
?>



Jul 16 '05 #9
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
}
?>


Jul 16 '05 #10
Geoff,

In mysql, case matters, so yes, he is referencing two seperate tables if
he changes case between the two queries. I'm curious as to why he's not
getting any errors with the code he's supplied. MySQL should complain
about the missing table, or the missing query, or the missing result
resource...

He didn't say whether he typed the code, or copied it from his source.

Jason

Geoff Berrow wrote:
Message-ID: <ja*********************@news1.central.cox.net> from Jason
Dumler contained the following:

Then your
script will hopefully tell you exactly what it's doing, leading you to
whatever the solution is.

He is still querying two different tables. TBLWorking is not the same as
tblworking is it?


Jul 16 '05 #11
On Sun, 29 Jun 2003 18:32:54 GMT, Jason Dumler
<du*********************@netscape.net> wrote:
In mysql, case matters, so yes, he is referencing two seperate tables if
he changes case between the two queries. I'm curious as to why he's not
getting any errors with the code he's supplied. MySQL should complain
about the missing table, or the missing query, or the missing result
resource...


MySQL's case-sensitivity for databases and tables depends on the
case-sensitivity of the underlying filesystem where the database/table files
are stored.

If you run it on Windows, you can get away with mixed case.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Airborne | last post by:
I am a newbie. In fact I am in school working on my Java project. Could someone please explain to me how to load a form from another form. I have a main form and from that form I want to show...
4
by: Larry | last post by:
Hi All, How I can open a new web page in a web form? I know response.redirect("...aspx") will re-direct the current page to another. However, what I want is to remain the current page unchange...
8
by: ryan | last post by:
that will make sure all fields are entered. make sure age is between 3- 99 and make sure the email is valid I had a decent search on google, nothing really comes up that is complete. I am...
2
blyxx86
by: blyxx86 | last post by:
I am very new to Access, and have only been using it for a month now. I have learned how to do a lot of things, but have been having problems making a form update a query that then is sent to a...
0
by: asad56 | last post by:
I am workin with a superstore managment project. I connect Access database with main form . Then it work properly. But now I connect same database with another table or field in another form which is...
10
by: Marren02 | last post by:
Hi, I recently just unsubscribed my other thread due to the fact that it went against the posting regulations... If you feel offended by what I posted, I apologize I need Code for a save...
0
by: jake hathaway | last post by:
hello , i am getting this error message "At least one of the From or Sender fields is required, and neither was found." i have added a contact form all the details are correct as far as i no...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.