/    Sign up×
Community /Pin to ProfileBookmark

Problem in Duplication of data and onenter key

Good day!

I have 2 problems with my code 1st is in the last operation name or the 04 Oper it was duplicate but the duplicate was only the operation name and the rest data was blank . I tried to debug it but I ca’n find where is wrong in my syntax. And the 2nd problem is for the enter key function or array, because my textbox I used array, and to move on the next textbox i used enter key, the problem is on the last date when i press enter key instead of move the cursor on the shift textbox it was save. I want to happen is after the last date and I press enter key the cursor was on the shift textbox then after i input data in shift and i press enter key it will save.

Here is my code:

[code=php]
<?php
if($rexist == 0)
{
$query = “SELECT t.operation_name, t.input_unit, t.output_unit FROM trace_operations t WHERE t.plt_typeno = ‘” . $_POST[“plt_typeno”] . “‘ AND t.operation_name IN(’02 Oper’,’03 Oper’,’04 Oper’) ORDER BY t.operation_name”;

$last_operation_name = “”;
$result = mysql_query($query);
if($result){
$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 width=’800′>”;
if ($last_operation_name != $row[“operation_name”]) echo $row[“operation_name”];
$last_operation_name = $row[“operation_name”];
echo “<input type=’hidden’ width=’400′ name=’opname[]’ value='” . $row[“operation_name”] . “‘ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’timein[]’ id=’timein” . $ctr . “‘ onkeypress=’return handleEnter(event,”timeout” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’timeout[]’ id=’timeout” . $ctr . “‘ onkeypress=’return handleEnter(event,”inqty” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ 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 size=’6′ 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 size=’6′ type=’text’ name=’idno[]’ id=’idno” . $ctr . “‘ onkeypress=’return handleEnter(event,”mcno” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’mcno[]’ id=’mcno” . $ctr . “‘ onkeypress=’return handleEnter(event,”varqty” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’varqty[]’ id=’varqty” . $ctr . “‘ onkeypress=’return handleEnter(event,”varplt” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’varplt[]’ id=’varplt” . $ctr . “‘ onkeypress=’return handleEnter(event,”dateshift” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’dateshift[]’ id=’dateshift” . $ctr . “‘ onkeypress=’return handleEnter(event,”shift” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ 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 width=’800′>”;
if ($last_operation_name != $row[“operation_name”]) echo $row[“operation_name”];
$last_operation_name = $row[“operation_name”];
echo “<input type=’hidden’ width=’400′ name=’opname[]’ value='” . $row[“operation_name”] . “‘ /></td>”;
echo “<input type=’hidden’ name=’opname[]’ value='” . $row[“operation_name”] . “‘ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’timein[]’ id=’timein” . $ctr . “‘ onkeypress=’return handleEnter(event,”timeout” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’timeout[]’ id=’timeout” . $ctr . “‘ onkeypress=’return handleEnter(event,”inqty” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ 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 size=’6′ 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 size=’6′ type=’text’ name=’idno[]’ id=’idno” . $ctr . “‘ onkeypress=’return handleEnter(event,”mcno” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’mcno[]’ id=’mcno” . $ctr . “‘ onkeypress=’return handleEnter(event,”varqty” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’varqty[]’ id=’varqty” . $ctr . “‘ onkeypress=’return handleEnter(event,”varplt” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’varplt[]’ id=’varplt” . $ctr . “‘ onkeypress=’return handleEnter(event,”dateshift” . $ctr . “”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’dateshift[]’ id=’dateshift” . $ctr . “‘ onkeypress=’return handleEnter(event,”shift”);’ /></td>”;
echo “ntt<td><input size=’6′ type=’text’ name=’shift[]’ id=’shift” . $ctr . “‘ onkeypress=’return handleEnter(event,”saveform”);’ /></td>”;
echo “nt</tr>”;
}
echo “</table>”;
echo “<p><input type=’submit’ value=’Save’ id=’saveform’ /></p>”;
echo “<input type=’hidden’ name=’plt_typeno’ value='” . $_POST[“plt_typeno”] . “‘ />”;
}
}
?>
[/code]

Any help is highly appreciated..

Thank you very much.. Ask me a question if my problem did not clear with you.?

Again, Thank you so much

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@rhodaroseauthorFeb 10.2011 — the code is olny part of my code where i encounter problem and the code that i post is if the plt_no did not exist the form will appear. And the form was appear, the code doing now is the last operation name the 04 Oper was duplicated in the database but only the operation name and the rest data was blank.

The second doing of my code is on the last text box for date after I insert date and I pressed enter key instead of the cursor was go to the shift textbox it goes to the save button so I have no chance to insert data in shift textbox.

On my first problem I tried to debug and i think the problem is from this code:
[code=php]
$query = "SELECT t.operation_name, t.input_unit, t.output_unit FROM trace_operations t WHERE t.plt_typeno = '" . $_POST["plt_typeno"] . "' AND t.operation_name IN('02 Oper','03 Oper','04 Oper') ORDER BY t.operation_name";

$last_operation_name = "";
$result = mysql_query($query);
if($result){
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;

[/code]


I tried to edit it but nothing was change. Honestly, i'm not good in coding specially in condition statement.

On my second problem I have no idea why does after I press enter key the save button was press.

Thank you
Copy linkTweet thisAlerts:
@rhodaroseauthorFeb 14.2011 — Good day!

I attached my wholde code for better understanding in my problem. I tried to resolved my problem by tracing the codes and I trace it but I tried to resolved but nothing has change in my output still the 04 Oper was duplicated.

Here is the code where i think I have problem:

[code=php]


//If not existing the form will appear to insert data.

if($rexist == 0)
{
$query = "SELECT t.operation_name, t.input_unit, t.output_unit FROM trace_operations t WHERE t.plt_typeno = '" . $_POST["plt_typeno"] . "' AND t.operation_name IN('02 Oper','03 Oper','04 Oper') ORDER BY t.operation_name";



$last_operation_name = "";
$result = mysql_query($query);
if($result){

//in this code I think I have a problem why the last operation name was duplicated, but I have no idea how can i resolved it. I'm not good in analyzing and in the syntax condition code.

//in this code happened is the last operation_name was fetch in this for loop and also in the if condition below so it was duplicated. I want to happened is in the last operation name in false on the if condition so that it could not duplicated.
$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 width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";

echo "ntt<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,"timeout" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,"inqty" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' 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 size='6' 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 size='6' type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,"mcno" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,"varqty" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,"varplt" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,"dateshift" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,"shift" . $ctr . "");' /></td>";

echo "ntt<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,"timein" . $tctr . "");' /></td>";
echo "nt</tr>";

}

}
if($totalrows > 0);
{
$row = mysql_fetch_array($result);
echo "nt<tr>";
echo "ntt<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "ntt<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,"timeout" . $ctr . "");' /></td>";
echo "ntt<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,"inqty" . $ctr . "");' /></td>";
echo "ntt<td><input size='6' 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 size='6' 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 size='6' type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,"mcno" . $ctr . "");' /></td>";
echo "ntt<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,"varqty" . $ctr . "");' /></td>";
echo "ntt<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,"varplt" . $ctr . "");' /></td>";
echo "ntt<td><input size='6' type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,"dateshift" . $ctr . "");' /></td>";
echo "ntt<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,"shift");' /></td>";
echo "ntt<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,"saveform");' /></td>";
echo "nt</tr>";
}
echo "</table>";
echo "<p><input type='submit' value='Save' id='saveform' /></p>";
echo "<input type='hidden' name='plt_typeno' value='" . $_POST["plt_typeno"] . "' />";
}


}
[/code]


[upl-file uuid=4e4d2912-3302-4944-93b0-54eee6919962 size=20kB]whole_code.txt[/upl-file]
×

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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...