Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    I'm having trouble getting a result from a simple SELECT query using a POST form. Any clue what I'm doing wrong?
    Code:
    <?php
    if(isset($_POST['search']))
    {
    include 'config.php';
    include 'dbopener.php';
     
    $stext = $_POST['stext'];
     
    $query = "SELECT * FROM eq2_idb WHERE name LIKE '%$stext%' LIMIT 0, 30";
    mysql_query($query)or die('Error, insert query failed');
     
    while($row= mysql_fetch_assoc($result))
    {
    echo "Name: {$row['name']} <br>";
    }
     
    include 'dbcloser.php';
    }
    else
    {
    ?>
    <form method="post">
    <table align="center" width="800" border="1" cellspacing="1" cellpadding="2">
    <tr> 
    <td width="100">Search Item Name:</td>
    <td><input name="stext" type="text" id="stext"></td>
    </tr>
    <tr>
    <td></td>
    <td><input name="search" type="submit" id="search" value="Search"></td>
    </tr>
    </table>
     
    </form>
    <?php
    }
    ?>
    
    I simply get no return and it boots back to the Form rather than echoing the result.
    Owner - http://www.project-guild.com (in development)

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    You do not assign anything to $result.

    Change
    PHP Code:
    mysql_query($query)or die('Error, insert query failed'); 
    to
    PHP Code:
    $result mysql_query($query)or die('Error, insert query failed'); 
    Try that.

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Yet another situation where PHP's retardedness stopped you from finding a solution faster. I strongly recommend you set error reporting all the way up for all of your development projects. Of course your code should never have errors, but it even shouldn't have notices.

    PHP Code:
    error_reporting(E_ALL); 
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    Quote Originally Posted by bfsog
    You do not assign anything to $result.

    Change
    PHP Code:
    mysql_query($query)or die('Error, insert query failed'); 
    to
    PHP Code:
    $result mysql_query($query)or die('Error, insert query failed'); 
    Try that.
    This worked like a charm. Thanks!
    Owner - http://www.project-guild.com (in development)

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Also inside your or die() part you should, at least while developing, echo out mysql_error().

    PHP Code:
    $result mysql_query($query)or die("Error Message: " mysql_error()); 

  7. #6
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    Yes, I've started doing that to ensure I can quickly clean up any mistakes I make, which are many
    Owner - http://www.project-guild.com (in development)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:11 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com