473,890 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($qu ery);
$number = mysql_numrows($ result);
for ($i=0; $i<$number; $i++) {

$CompanyName = mysql_result($r esult,$i,"Compa ny");
$ContactName = mysql_result($r esult,$i,"Conta ct");

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 4022
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.b e> 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($qu ery);
$number = mysql_numrows($ result);
for ($i=0; $i<$number; $i++) {

$CompanyName = mysql_result($r esult,$i,"Compa ny"); $ContactName =
mysql_result($r esult,$i,"Conta ct");

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************ *********@netsc ape.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($qu ery);

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($r esult,$i,"Compa ny");
$ContactName = mysql_result($r esult,$i,"Conta ct");

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************ *********@netsc ape.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

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

Similar topics

0
2724
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 another form called view cart. I need to load the swing form when they press the view cart button, but it says I can not call invokeandwait from an event dispatcher....Help.
4
1510
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 and by clicking a button on current form to open a new web page. Any assistance is highly appreciate.
8
1340
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 sure that it is out there somewhere?
2
2053
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 report. Here is what I would like to accomplish... I have a table that has customers, and another table that has salesperson. I want to link certain salespersons to an individual customer. Also, each salesperson may have more than one customer. ...
0
1987
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 child of main form not working. Main form stil working but when try to open child a message show as Please select a valid SQL statement as "Select", "Delet" or "Updat" I am working with Access . I connect database in...
10
4441
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 button... this save button must be able to... ---save data! ---must have a save as function...obviously due to the fact that some data might be new ---Explore the windows directory as default I therefore also need code for a load button with the...
0
1418
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 please can someone check over them and help me fix this this is the web address to the page where the error is http://www.onlinegamesleague.co.uk/jakesportfolio/contact.aspx this is my source code <%@ Page Title="Jake Hathaway's Portfolio l...
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10811
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10919
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10461
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3275
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.