Problem with results of form

This is a discussion on "Problem with results of form" within the PHP Forum section. This forum, and the thread "Problem with results of form are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 7th, 2006, 12:05
New Member
Join Date: Nov 2006
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with results of form

Here is the bare bones of a PHP form that I've cobbled together.

It works fine if the results are true. The information is shown perfectly.
The problem comes when the results are not found. Instead of showing the 'error' message on screen it shows the top of the 'found' bit and no content below that.

I'm assuming that I've missed out something very simple - but I can't see it.

Can anyone help?

PHP: Select all

<?php

    $con 
mysql_connect("localhost","user","login");
    if (!
$con)
        {
            die(
'Could not connect: ' mysql_error());
        }

    
mysql_select_db("dbase"$con);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>simple form</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" type= "text/css" href="style.css">
    </head>
    <body>
        <?php
            
if ($submit) {

                
// process form
                
if ($vars != "this") {

                
$res $h "x"  $vars "x" $w;

                } else {

                
$res $h "x" $w;

                }

                
$result01 mysql_query("SELECT * FROM tablename WHERE res = '$res'");

                if (
$result01 != NULL) {

                print 
"Your selection" $res ". ";

                while(
$resultrow mysql_fetch_array($result01))

                {
                     
some queries off the table

                    
print "some repeated stuff";
                }
                print 
"end of page";
                }

             else {
                    print 
"You selected " $res " but it could not be found. Please try again.";
                }

            } else {

                  
// display form

        
?>
        <form method="post" action="<?php echo $PHP_SELF ?>">

        // form content

        </form>
        <?php

            
// end if

        
?>

    </body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 7th, 2006, 12:36
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem with results of form

If something isn't found, you'll still get back a true result but an empty result set - that's what you're seeing. What you're checking for is an erroneous piece of SQL which won't be the case - you'll have a correct piece of SQL but one that retruns no records.

Suggestion ... add a counter within your while loop that fetches queries back, and if that counter still has a zero value when you finish the loop, output your "no match" message.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 7th, 2006, 14:35
New Member
Join Date: Nov 2006
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem with results of form

Thank you for your suggestion Grahame.

It works fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
form, null, php, problem, result

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Publicly viewable form results? wealthy199 Starting Out 5 Sep 27th, 2007 14:59
Getting form results to email as an .html griffster122 Starting Out 1 May 29th, 2007 01:44
Viewing form results ??????? cat101 PHP Forum 3 Apr 25th, 2006 23:57
PHP form results $PHP_self is blank jamina1 PHP Forum 17 Sep 23rd, 2005 16:13
Submitting Web form results to a database theproman23 Databases 2 Jun 30th, 2005 13:21


All times are GMT. The time now is 13:55.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved