query returns no results

Posted on 2006-03-29
Last Modified: 2013-12-12
Hi i and trying to create an update function for my web site i have two scripts one to take the users input and a second to search for the valu and output the record in a text field for editing before a third script is used to updte the data, i am having trouble with the first 2 as the scripts run but there is nothing outputted in the textarea i have listed the code below, can anyone help?


 $searchterm = strip_tags(trim($_POST['searchterm']));

 $label_array = array (
                   "searchterm" => "Please enter your search term");

foreach ($_POST as $field => $value);


   echo "<p><hr>
      <form action='staff_update_results.php' method='POST'>
      <table width='95%' border='0' cellspacing='0' cellpadding='2'>

      <tr><td align='right'><B>{$label_array['searchterm']}:</br></td>
        <td><input type='text' name='results' size='65' maxlength='65'> </td>
      <p><input type='submit' value='Run search'>



    $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
    $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");

$query = "SELECT * FROM staff WHERE lastname = '$_POST[searchterm]'";
$result = mysql_query($query)  or die(mysql_error());

$row = mysql_fetch_array($result,MYSQL_ASSOC);

$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result,MYSQL_ASSOC);

$label_array = array (
                  "searchresults" => "The search retured the results");

foreach ($_POST as $field => $value);

echo "<p><hr>
      <form action='staff_update.php' method='POST'>
      <table width='80%' border='0' cellspacing='0' cellpadding='2'>

      <tr><td align='right'><B>{$label_array['searchresult']}:</br></td>
        <td><textarea name='searchresults' cols='40' rows='6'>

 </textarea> </td>

      <p><input type='submit' value='Go Back'>";

Question by:Karl01
    LVL 33

    Accepted Solution

    foreach ($_POST as $field => $value); <-- there's a semicolon that shouldn't be.

    There's also nothing within the textarea tags.  You'll need to put something to do with $row in there.

    echo "...<textarea>";
    echo "</textarea>...";

    Author Comment

    Thanks for the reply but tried that and messed about with a few thing still giving me a blank textarea! any other ideas?

    LVL 33

    Expert Comment

    checked to make sure there are results returned?

    Author Comment

    how do u mean? I have checked the query in the mysql prompt and the value I entered is in the table and does return a result!
    LVL 3

    Expert Comment

    Are you wanting to simply check whether any results have been returned, or are you trying to actually print the results?
    LVL 8

    Expert Comment

    Well,the problem is with the text area itself
    u have put nothing between the opening and closing tags for Txt Area
    <text area><?Put some value over here(output of the query?></Text Area>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now