/    Sign up×
Community /Pin to ProfileBookmark

Retrieving data from database and displaying in textbox when the button click

I search about the code for retrieving data from database when the retrieve button was click. But I can’t find any codes that similar in my situation.

Here is the flow of my system. I have plt_no and a retrieve button. The retrieve button is to check if the plt_no is already exist or not if it is already exist the data from the database will appear in the text area/textbox and if the plt_no did not exist there’s a message that the id number did not exist and I can input data in the textboxes.

I have an idea of using this code:
This code is to check if the Retrieve button is click and the plt_no is the data which the retrieve depend on. Like for example the user put plt_no 111 and when the user click the Retrieve button, if the 111 is already exist the data will appear in the textboxes but if not there’s a message appear saying the plt no did not exist.

[code]
if(isset($_POST[‘Retrieve’]))
$plt_no = $_POST[‘plt_no’];
[/code]

And I have search code for retrieving data:

[code=php]

<?php
// Connects to your Database
mysql_connect(“your.hostaddress.com”, “username”, “password”) or die(mysql_error());
mysql_select_db(“Database_Name”) or die(mysql_error());
$data = mysql_query(“SELECT * FROM friends WHERE pet=’Cat'”)
or die(mysql_error());
Print “<table border cellpadding=3>”;
while($info = mysql_fetch_array( $data ))
{
Print “<tr>”;
Print “<th>Name:</th> <td>”.$info[‘name’] . “</td> “;
Print “<th>Color:</th> <td>”.$info[‘fav_color’] . “</td> “;
Print “<th>Food:</th> <td>”.$info[‘fav_food’] . “</td> “;
Print “<th>Pet:</th> <td>”.$info[‘pet’] . ” </td></tr>”;
}
Print “</table>”;
?>
[/code]

I attach my full code.

My problem is how can I used that code and if that code is the code I need to used for retrieving data.

I have an idea but i am luck of knowledge in coding

Any help is highly appreciated I ma willing to learn and share

Thank you

[upl-file uuid=8372d500-7398-4614-9329-66412498ff93 size=13kB]retrieve.txt[/upl-file]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Alan_PJan 04.2011 — Check to see if results are returned - if so display information, if not display message.

[CODE]echo "<table width='500' border='0' cellspacing='0' cellpadding='2'>";

$query = "SELECT * FROM friends WHERE pet='Cat'";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$row = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);
if ($num_results > 0) {

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$name = stripslashes($row['name']);
$fav_color = stripslashes($row['fav_color']);
$fav_food = stripslashes($row['fav_food']);
$pet = stripslashes($row['pet']);
echo "
<tr>
<th>Name:</th><td>" . $name . "</td>
<th>Color:</th><td>" . $fav_color . "</td>
<th>Food:</th><td>" . $fav_food . "</td>
<th>Pet:</th><td>" . $pet . "</td>
</tr>
";
}

} else {

echo "<tr><td>There are no results at this time.</td></tr>";
}

echo "</table>";
[/CODE]
Copy linkTweet thisAlerts:
@rhodaroseauthorJan 05.2011 — When I insert plt_no in a textbox then i click the retrieve button if the plt_no is already exist the data was appear in a textbox and if not it will not appear.My problem is I have difficulty in combining of codes. I want to add the codes in my codes:

[code=php]
if($_POST["enum_plt"] && $_POST["plt_typeno"])
{
$query = "SELECT * FROM plt_type WHERE plt_typeno = '" . $_POST["plt_typeno"] . "'";
$result = mysql_query($query);
if($result)
{
$rexist = 1;
echo "<p>PLT No:<input type='text' name='plt_no' onkeypress='return handleEnter(event,"plt_date");' /></br />";
echo "PLT Date:<input type='text' name='plt_date' onkeypress='return handleEnter(event,"bom0");' /></p>";
echo "<p><input type='Button' value='Retrieve' id='Retrieve' name='Retrieve' /></p>";
echo "<table>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$tctr = $ctr + 1;
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td><input type='text' name='bom[]' id='bom" . $ctr . "' onkeypress='return handleEnter(event,"qty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["plt_chemicals"];
echo "<input type='hidden' name='chem[]' value='" . $row["plt_chemicals"] . "' /></td>";
echo "ntt<td><input type='text' name='qty[]' id='qty" . $ctr . "' onkeypress='return handleEnter(event,"part" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='part[]' id='part" . $ctr . "' onkeypress='return handleEnter(event,"lot" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='lot[]' id='lot" . $ctr . "' onkeypress='return handleEnter(event,"bom" . $tctr . "");' /></td>";
echo "nt</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td><input type='text' name='bom[]' id='bom" . $ctr . "' onkeypress='return handleEnter(event,"qty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["plt_chemicals"];
echo "<input type='hidden' name='chem[]' value='" . $row["plt_chemicals"] . "' /></td>";
echo "ntt<td><input type='text' name='qty[]' id='qty" . $ctr . "' onkeypress='return handleEnter(event,"part" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='part[]' id='part" . $ctr . "' onkeypress='return handleEnter(event,"lot" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='lot[]' id='lot" . $ctr . "' onkeypress='return handleEnter(event,"b1");' /></td>";
echo "nt</tr>";
}
echo "</table>";

echo "<p>&nbsp;</p>";
echo "<table>";
echo "<tr><td>B1</td><td><input type='text' name='b1' id='b1' onkeypress='return handleEnter(event,"sc2");' /></td></tr>";
echo "<tr><td>SC2</td><td><input type='text' name='sc2' id='sc2' onkeypress='return handleEnter(event,"timein0");' /></td></tr>";
echo "</table>";
echo "<p>&nbsp;</p>";

$query = "SELECT * FROM trace_operations WHERE plt_typeno = '" . $_POST["plt_typeno"] . "' AND operation_name IN ('Operation1' , 'Operation2' , 'Operation3')ORDER BY operation_name";
$last_operation_name = "";
$result = mysql_query($query);
if($result)
{
$rexist = 1;
echo "<table>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "nt<tr>";
echo "ntt<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "ntt<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,"timeout" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,"inqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,"outqty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "ntt<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,"idno" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "ntt<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,"mcno" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,"varqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,"varplt" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,"dateshift" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,"shift" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,"timein" . $tctr . "");' /></td>";
echo "nt</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "ntt<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,"timeout" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,"inqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,"outqty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "ntt<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,"idno" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "ntt<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,"mcno" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,"varqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,"varplt" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,"dateshift" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,"shift");' /></td>";
echo "ntt<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,"saveform");' /></td>";
echo "nt</tr>";
}
echo "</table>";
}
}
}
[/code]


Some forum suggest this codes:
<i>
</i>&lt;Input type="Text" name="bom" value=" &lt;?php if(empty($info['bom'])){echo '';}else {echo $info['bom'];}?&gt; "&gt;


Thank you
Copy linkTweet thisAlerts:
@rhodaroseauthorJan 05.2011 — I have the code I want to add for retrieving data:

[code=php]
$query = "SELECT plt_no FROM plt_transact WHERE plt_no= '" . $_POST["plt_no"] . "'";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$row = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);
if ($num_results > 0) {
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
[/code]


Is it that code is right?for retrieving data?

My question is it automatically that when I insert plt_no then i click retrieve button it plt_no is exist the data will appear in the textboxes but I don't know how can I appear it and if the plt_no did not exist the textboxes is blank and theres a message that saying plt no did not exist.

[code=php]
if($_POST["enum_plt"] && $_POST["plt_typeno"])
{
$query = "SELECT * FROM plt_type WHERE plt_typeno = '" . $_POST["plt_typeno"] . "'";
$result = mysql_query($query);
if($result)
{
$rexist = 1;


$query = "SELECT plt_no FROM plt_transact WHERE plt_no= '" . $_POST["plt_no"] . "'";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$row = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);
if ($num_results > 0) {
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo "<p>PLT No:<input type='text' name='plt_no' onkeypress='return handleEnter(event,"plt_date");' /></br />";
echo "PLT Date:<input type='text' name='plt_date' onkeypress='return handleEnter(event,"bom0");' /></p>";
echo "<p><input type='Button' value='Retrieve' id='Retrieve' name='Retrieve' /></p>";
echo "<table>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$tctr = $ctr + 1;
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td><input type='text' name='bom[]' id='bom" . $ctr . "' onkeypress='return handleEnter(event,"qty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["plt_chemicals"];
echo "<input type='hidden' name='chem[]' value='" . $row["plt_chemicals"] . "' /></td>";
echo "ntt<td><input type='text' name='qty[]' id='qty" . $ctr . "' onkeypress='return handleEnter(event,"part" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='part[]' id='part" . $ctr . "' onkeypress='return handleEnter(event,"lot" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='lot[]' id='lot" . $ctr . "' onkeypress='return handleEnter(event,"bom" . $tctr . "");' /></td>";
echo "nt</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td><input type='text' name='bom[]' id='bom" . $ctr . "' onkeypress='return handleEnter(event,"qty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["plt_chemicals"];
echo "<input type='hidden' name='chem[]' value='" . $row["plt_chemicals"] . "' /></td>";
echo "ntt<td><input type='text' name='qty[]' id='qty" . $ctr . "' onkeypress='return handleEnter(event,"part" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='part[]' id='part" . $ctr . "' onkeypress='return handleEnter(event,"lot" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='lot[]' id='lot" . $ctr . "' onkeypress='return handleEnter(event,"b1");' /></td>";
echo "nt</tr>";
}
echo "</table>";

echo "<p>&nbsp;</p>";
echo "<table>";
echo "<tr><td>B1</td><td><input type='text' name='b1' id='b1' onkeypress='return handleEnter(event,"sc2");' /></td></tr>";
echo "<tr><td>SC2</td><td><input type='text' name='sc2' id='sc2' onkeypress='return handleEnter(event,"timein0");' /></td></tr>";
echo "</table>";
echo "<p>&nbsp;</p>";

$query = "SELECT * FROM trace_operations WHERE plt_typeno = '" . $_POST["plt_typeno"] . "' AND operation_name IN ('Operation1' , 'Operation2' , 'Operation3')ORDER BY operation_name";
$last_operation_name = "";
$result = mysql_query($query);
if($result)
{
$rexist = 1;
echo "<table>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "nt<tr>";
echo "ntt<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "ntt<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,"timeout" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,"inqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,"outqty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "ntt<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,"idno" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "ntt<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,"mcno" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,"varqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,"varplt" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,"dateshift" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,"shift" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,"timein" . $tctr . "");' /></td>";
echo "nt</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "ntt<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,"timeout" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,"inqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,"outqty" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "ntt<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,"idno" . $ctr . "");' /></td>";
echo "ntt<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "ntt<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,"mcno" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,"varqty" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,"varplt" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,"dateshift" . $ctr . "");' /></td>";
echo "ntt<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,"shift");' /></td>";
echo "ntt<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,"saveform");' /></td>";
echo "nt</tr>";
}
echo "</table>";
}
}
}
}
}
[/code]

this code is incomplete, can someone told me what is the missing code to view the retrieve data?and how does the retrieve works.

Thank you
×

Success!

Help @rhodarose spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...