Jump to content

Fetch db data depending on selected drop down value


cainam29

Recommended Posts

I want to pull up the data that corresponds to the value of the drop down and show it to a text area within a fieldset, I want my page to just initially show the drop down then after selecting a value it will show the data in a text area without refreshing the page, here is the code:

<div id="mainContent">
<table width="619" border="0" align="center">
<td align="center"><form id="form1" name="form1" method="post" action="" >
<fieldset>
<legend><strong>EA</strong></legend>
<p> 
<select name="ea_name" id="ea_name">
<option value="" selected="selected">Please select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</p>
</fieldset>
</form></td>
</table>

<div id="results"></div>
</div>

Here is the code that I've tried that will pull up data and show to a text area but all im getting is No results found.

<?php
require 'include/DB_Open.php';

$ea_name = $_POST['ea_name'];

$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";

$myData = mysql_query($sql);

//to count if there are any results
$numrow = mysql_num_rows($myData);

if($numrow == 0)
{
    echo "No results found.";
}
else
{
echo '<fieldset><legend><strong>Information</strong></legend><p>
<table width="auto" height="172" border="0">
<tr><th>Error</th></tr>
<tr><th>Resolution</th></tr>
<tr><th>Contact/s</th></tr>';

while($info = mysql_fetch_array($myData)) 
{
echo "<form action='retrieve.php' method='post'>";

echo"<tr>"; 
echo  "<td align='center'>" . $info['error'] . "<input type=hidden name=error value=" . $info['error'] . " </td>";
echo  "<td align='center'>" . $info['resolution'] . "<input type=hidden name=resolution value=" . $info['resolution'] . " size='11' maxlength='11' /> </td>"; 
echo  "<td align='center'>" . $info['contacts'] . "<input type=hidden name=contacts value=" . $info['contacts'] . "' /> </td>"; 
echo "</tr>"; 
echo "</form>";
}
}
echo "</fieldset>"; 

include 'include/DB_Close.php';
?>
Link to comment
Share on other sites

Just do some basic diagnostics then, first you need to sanitize the value of your post.  According to your select menu it's an integer but I assume that is just an example, so you need to use mysql_real_escape_string() and then add mysql_error() after the query to see why the query is failing.

$ea_name = mysql_real_escape_string($_POST['ea_name']);
$myData = mysql_query($sql);
echo mysql_error();
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.