Form Problem ! Please Help !

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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

    James Guest

  2. Similar Questions and Discussions

    1. Problem with CFM form.
      Hi everyone. I have a website for signing up for an event. It was working fine, but now everytime anyone tries to open the registration page they...
    2. Form Problem
      Hi, I've got an intranet site that allows a user to view a weekly diary on a page. Clicking on an item on a particular day...fires up a modal...
    3. Simple Form Problem!
      Hi, I am using a simple form 2 email program. I ama experienced programmer, But I feel very bad, as I am unable to fix this problem. All seems...
    4. is this a form problem?
      I have been wrestling with this problem for the past couple weeks, and I can't seem to get a solid answer from anyone I talk to...hopefully one or...
    5. problem with form in php
      Hi, i have a problem with a form. In my page there is the following code: ...
  3. #2

    Default Re: Form Problem ! Please Help !

    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" <junk@sotto.be> wrote:
    >just a quick idea...
    >try if($company!=''){ ... and if($name!='') { ....
    James Guest

  4. #3

    Default Re: Form Problem ! Please Help !

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

  5. #4

    Default Re: Form Problem ! Please Help !

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

  6. #5

    Default Re: Form Problem ! Please Help !


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

  7. #6

    Default Re: Form Problem ! Please Help !

    Message-ID: <cq6sfvoqnrinsemhc5sl04cf5r10hg1ass@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 [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  8. #7

    Default Re: Form Problem ! Please Help !

    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)
    sotto Guest

  9. #8

    Default Re: Form Problem ! Please Help !

    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
    >>}
    >>?>
    >
    >
    Jason Dumler Guest

  10. #9

    Default Re: Form Problem ! Please Help !

    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
    <dumlerjason_bugger_spam@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
    >>>}
    >>>?>
    >>
    >>
    James Guest

  11. #10

    Default Re: Form Problem ! Please Help !

    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
    > <dumlerjason_bugger_spam@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
    >>>>}
    >>>>?>
    >>>
    >>>
    >
    Jason Dumler Guest

  12. #11

    Default Re: Form Problem ! Please Help !

    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: <jaELa.534628$vU3.480205@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?
    >
    Jason Dumler Guest

  13. #12

    Default Re: Form Problem ! Please Help !

    On Sun, 29 Jun 2003 18:32:54 GMT, Jason Dumler
    <dumlerjason_bugger_spam@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 (andy@andyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage analysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139