Create Table with Multiple Dynamic Field in PHP - javascript

Only I can create a table row but I want to create multiple tables row I get an error.
I think that the error in the query but I do not know how to find a solution
How can I add more than one table?
How do I need to make a change in the query unit?
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
$con=mysql_connect("localhost","root","password");
$table=mysql_select_db("databaseName") or die (mysql_error());
if(isset($_POST['submit']))
{
$count2 = $_POST["hidden"];
for($i=1;$i<=$count2;$i++)
{
$save = mysql_query("CREATE TABLE `".$_POST["dbName"]."`.`".$_POST["TableName"]."` ( `".$_POST["ColonName$i"]."` INT(".$_POST["LengthValues$i"].") NOT NULL COMMENT '".$_POST["Comments$i"]."' ) ENGINE = InnoDB");
}
if($save)
{
echo '<script type="text/javascript">alert("Saved Success !");</script>';
}
else
{
echo '<script type="text/javascript">alert("Failed");</script>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Multiple Save </title>
</head>
<body>
<center>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get"> <!-- Form for generate no of times -->
<table align="center">
<tr>
<th colspan="3" align="center">Order Num Of Rows</th>
</tr>
<tr>
<td>VT ismi</td>
<td><input type="text" name="dbName" /></td>
<td>TabloAd</td>
<td><input type="text" name="TableName" /></td>
<td>No Of</td>
<td><input type="text" name="no" /></td>
<td><input type="submit" name="order" value="Generate" /></td>
</tr>
</table>
</form><!-- End generate Form -->
<!---- Create multiple Save Form,-->
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center">
<tr>
<th colspan="3" align="left">Dynamic multiple Save To MySql</th>
</tr>
<tr>
<td>tabloAdi</td>
<td>VT</td>
<td>Colon Name</td>
<td>Leght</td>
<td>Comment</td>
</tr>
<?php
if(isset($_GET['order']))
{
$count = $_GET['no']-1; //get the num of times as numeric
while($i <= $count)// loop by using while(),NOTE the looping dynamic textbox must be under the for loop othet must be outside of while()
{
$i++;
?>
<tr>
<td><input type="hidden" name="TableName" value="<?php echo $_GET["TableName"]; ?>"/></td>
<td><input type="hidden" name="dbName" value="<?php echo $_GET["dbName"]; ?>"/></td>
<td><input type="text" name="ColonName<?php echo $i; ?>" /></td>
<td><input type="text" name="LengthValues<?php echo $i; ?>" /></td>
<td><input type="text" name="Comments<?php echo $i; ?>" /></td>
</tr>
<?php
}}
?>
<tr>
<td colspan="3" align="center">
<input type="hidden" name="hidden" value="<?php echo $i; ?>" /><!-- Get max count of loop -->
<input type="submit" name="submit" value="Save Multiple" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>

Related

How to update data from dynamically created table to database in php

I have create a table using php dynamically. But i need to update some of the cell value depending on user input. But i can't figure out how to do that. my codes are given below.
I have found a way to make names an array is to use [] in names attribute from stackoverflow. but it didn't work for me.If i echo $_POST['std_name'] in while loop or outside of loop only the last row of student name is counted. Please Someone help. I am stuck here for 3 days.
<form action="" method="post">
<table>
<tr>
<th>Student ID</th>
<th>Student Name</th>
<th>Student Father Name</th>
<th>Student Mother Name</th>
<th>Student Parents Mobile Number</th>
<th>Student Mobile Number</th>
<th>Student Batch Name</th>
<th>Student College Name</th>
<th>Student Gender</th>
<th>Student Picture</th>
<th>Student Admit Date</th>
<th>January</th>
<th>February</th>
<th>March</th>
<th>April</th>
<th>May</th>
<th>June</th>
<th>July</th>
<th>August</th>
<th>September</th>
<th>October</th>
<th>November</th>
<th>December</th>
</tr>
<tr>
<?php
$host="localhost";
$username="root";
$password="";
$db="paragon_first_year";
$qry="select * from `student_info`";
$con=mysqli_connect($host,$username,$password);
mysqli_select_db($con,$db);
$res=mysqli_query($con,$qry);
if(mysqli_num_rows($res)>0){
while($dt=mysqli_fetch_array($res)){?>
<td><input type="text" name="std_id[]" value="<?php echo $dt['std_id']?>"></td>
<td><input type="text" name="std_name[]" value="<?php echo $dt['std_name']?>"></td>
<td><input type="text" name="std_father_name[]" value="<?php echo $dt['std_father_name']?>"></td>
<td><input type="text" name="std_mother_name[]" value="<?php echo $dt['std_mother_name']?>"></td>
<td><input type="text" name="std_parent_mob[]" value="<?php echo $dt['std_parents_mob_no']?>"></td>
<td><input type="text" name="std_mob[]" value="<?php echo $dt['std_mob_no']?>"></td>
<td><?php echo $dt['std_batch_name'] ?></td>
<td><?php echo $dt['std_college_name'] ?></td>
<td><?php echo $dt['std_gender'] ?></td>
<td><img style="height:100px;width:100px;" src="uploadImage/<?php echo $dt['std_name']."_".$dt['std_pic'] ?>" alt=""></td>
<td><?php echo $dt['std_admit_date'] ?></td>
<td><input type="text" name="jan[]" value="<?php echo $dt['january']?>"></td>
<td><input type="text" name="feb[]" value="<?php echo $dt['february']?>"></td>
<td><input type="text" name="mar[]" value="<?php echo $dt['march']?>"></td>
<td><input type="text" name="apr[]" value="<?php echo $dt['april']?>"></td>
<td><input type="text" name="may[]" value="<?php echo $dt['may']?>"></td>
<td><input type="text" name="jun[]" value="<?php echo $dt['june']?>"></td>
<td><input type="text" name="jul[]" value="<?php echo $dt['july']?>"></td>
<td><input type="text" name="aug[]" value="<?php echo $dt['august']?>"></td>
<td><input type="text" name="sep[]" value="<?php echo $dt['september']?>"></td>
<td><input type="text" name="oct[]" value="<?php echo $dt['october']?>"></td>
<td><input type="text" name="nov[]" value="<?php echo $dt['november']?>"></td>
<td><input type="text" name="dec[]" value="<?php echo $dt['december']?>"></td>
</tr><?php
}
}
?>
</table>
<center>
<input type="submit" name="submit" value="Update Data">
</center>
</form>
</body>
my table is showing nicely
hope someone help. Thanks in advance.
You can use array keys to pass information. In this example, the first key is the database primary key, and the second key is the variable name.
The resulting array would look something like this:
$row[123][std_name] = 'joe';
$row[123][std_father_name] = 'bob';
... etc
$row[124][std_name] = 'sally';
$row[124][std_father_name] = 'john';
...etc
Then, as you iterate through the rows, you get the key (123) to use to update the database, as in where std_id=123.
Note: I have used prepared statements to show updating the database. This is essential. Never put variables in a query using concatenation ( i.e., "select * from table where id='$id'")
Lastly, note the structure. Start with PHP, no print or echo statements. This allows you to work with user input and then redirect. First initialize, then work with user input, then do page logic, and lastly get out of php and output the view (html)
This example is not copy and paste; it has things that need to be filled in, and probably debugged. It is merely intended to show the big picture.
<?php
// initialize
$host="localhost";
$username="root";
$password="";
$db="paragon_first_year";
$con=mysqli_connect($host,$username,$password);
// a simple wrapper to make the prepared query more manageable
// see https://phpdelusions.net/mysqli/mysqli_connect#helper
function prepared_query($mysqli, $sql, $params, $types = "")
{
$types = $types ?: str_repeat("s", count($params));
$stmt = $mysqli->prepare($sql);
$stmt->bind_param($types, ...$params);
$stmt->execute();
return $stmt;
}
// work with user input
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$dataRows = (array)$_POST['data'];
foreach($dataRows as $id=>$data) {
$sql = "INSERT INTO student_info SET std_name=?, std_father_name=?, " .
// etc .
"WHERE std_id=?";
$params = array(
$data['std_name'],
$data['std_father_name'],
// etc...
$id
);
// this does the prepare, bind, and execute... Yes, I could just do the
// bind and execute here, but the time savings isn't worth the trouble.
$stmt = prepared_query($con, $sql, $params);
}
// always redirect after a POST
header('Location: /path/to/next/page/or/this/page');
die;
}
// no user input; ok to use plain old query.
$qry="select * from `student_info`";
mysqli_select_db($con,$db);
$res=mysqli_query($con,$qry);
?>
<html>
...
<form action="" method="post">
<table>
<tr>
<th>Student ID</th>
<th>Student Name</th>
<th>Student Father Name</th>
<th>Student Mother Name</th>
<th>Student Parents Mobile Number</th>
<th>Student Mobile Number</th>
<th>Student Batch Name</th>
<th>Student College Name</th>
<th>Student Gender</th>
<th>Student Picture</th>
<th>Student Admit Date</th>
<th>January</th>
<th>February</th>
<th>March</th>
<th>April</th>
<th>May</th>
<th>June</th>
<th>July</th>
<th>August</th>
<th>September</th>
<th>October</th>
<th>November</th>
<th>December</th>
</tr>
<!-- don't need mysqli_num_rows; the while won't loop if no results -->
<?php while($dt=mysqli_fetch_array($res)): ?>
<tr>
<td><?= $dt['std_id'] ?></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['std_name']" value="<?= $dt['std_name'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['std_father_name']" value="<?= $dt['std_father_name'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['std_mother_name']" value="<?= $dt['std_mother_name'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['std_parent_mob']" value="<?= $dt['std_parents_mob_no'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['std_mob']" value="<?= $dt['std_mob_no'] ?>"></td>
<td><?= $dt['std_batch_name'] ?></td>
<td><?= $dt['std_college_name'] ?></td>
<td><?= $dt['std_gender'] ?></td>
<td><img style="height:100px;width:100px;" src="uploadImage/<?= $dt['std_name']."_".$dt['std_pic'] ?>" alt=""></td>
<td><?= $dt['std_admit_date'] ?></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['jan']" value="<?= $dt['january'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['feb']" value="<?= $dt['february'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['mar']" value="<?= $dt['march'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['apr']" value="<?= $dt['april'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['may']" value="<?= $dt['may'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['jun']" value="<?= $dt['june'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['jul']" value="<?= $dt['july'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['aug']" value="<?= $dt['august'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['sep']" value="<?= $dt['september'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['oct']" value="<?= $dt['october'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['nov']" value="<?= $dt['november'] ?>"></td>
<td><input type="text" name="data[<?= $dt['std_id'] ?>]['dec']" value="<?= $dt['december'] ?>"></td>
<?php endwhile; ?>
</tr>
</table>
<center>
<input type="submit" name="submit" value="Update Data">
</center>
</form>
</body>

I want particular cell value when i clicking on it

<?php
$con = mysql_connect('localhost','root','');
$db = mysql_select_db("demo",$con);
?>
<!doctype html>
<html>
<head>
<title>Demo</title>
<!--JAVASCRIPT -->
<script src="http://code.jquery.com/jquery-1.9.1.min.js" ></script>
<script>
$(document).ready(function(){
$("#myTable td").click(function() {
var column_num = parseInt( $(this).index() ) + 1;
var row_num = parseInt( $(this).parent().index() )+1;
//$("#result").html( "Row_num =" + row_num + " , Column_num ="+ column_num );
alert(row_num);
});
});
</script>
</head>
<body>
<!--<div id="result"> </div>-->
<table id="myTable" border="1" style="border-collapse: collapse;" cellpadding="8">
<tr>
<th>Name</th>
<th>Qty</th>
<th>Amount</th>
<th>Total</th>
</tr>
<?php
$sQ = "select * from tbl_demo";
$eQ = mysql_query($sQ);
while($fQ=mysql_fetch_array($eQ))
{
$name = $fQ['Name'];
$qty = $fQ['Qty'];
$amt = $fQ['Amount'];
//$total
$total = $fQ['Total'];
?>
<tr>
<td><input type="text" name="name" value="<?php echo $name; ?>" onchange="add($qty,$amt)"/> </td>
<td><input type="number" name="name" value="<?php echo $qty; ?>"/></td>
<td><input type="number" name="name" value="<?php echo $amt; ?>"/></td>
<td><input type="number" name="name" value="<?php echo $total; ?>"/></td>
</tr>
<?php
}
?>
<tr>
<td colspan="3" style="padding-left:400px"> Total </td>
<td class="navigateTest"> <input type="number" name="name" value=""/> </td>
</tr>
<tr>
<td colspan="4" class="navigateTest"> <input type="button" name="submit" id="submit" value="Submit"/> </td>
</tr>
</table>
</body>
</html>
Here is my code. I get index value of particular row nd column bt i can not find value of that cell.. I tried to solve that problem bt i can not understand code which i found..which are the different ways for that??
How i get data of particular cell?????
plz redirect me at right direction...

After pressing submit, I want it to display a 2nd form

I'm trying to submit a form, and after pressing the submit button I want the 2nd form to show up while still holding values (I have this part worked out). I was told to use the isset function but i'm unable to get it working. The code works fine (I haven't copied the php stuff in).
<!DOCTYPE html>
<html>
<head>
<title>Prac 2 Task 12</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="custinfo" >
<table>
<tr>
<td><label for="customerid">Customer ID (integer value): </label></td>
<td>
<input
type="text"
id="customerid"
name="customerid"
size="10"
value="<?php
echo isset($_POST['customerid'])
? htmlspecialchars($_POST['customerid'])
: ''; ?>"
/>
<?php echo $customerIDError ?>
</td>
<td style="color:red"></td>
</tr>
</table>
<p>
<input type="submit" name = "submit" value="Save Data"/>
<input type="reset" value="Reset Form" />
</p>
</form>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="custinfo" >
<table>
<tr>
<td><label for="username">Username: </label></td>
<td>
<input
type="text"
id="username"
name="username"
size="10"
value="<?php
echo isset($_POST['username'])
? htmlspecialchars($_POST['customerid'])
: ''; ?>"
/>
<?php echo $customerIDError ?></td>
<td style="color:red"></td>
</tr>
</table>
<p>
<input type="submit" name = "submit" value="Save Data"/>
<input type="reset" value="Reset Form" />
</p>
</form>
</body>
</html>
you can use jquery for that first you can define
$("#submit").click(function(){
$("#custinfo1").show();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Prac 2 Task 12</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?> " id="custinfo">
<table>
<tr>
<td>
<label for="customerid">Customer ID (integer value):</label>
</td>
<td>
<input type="text" id="customerid" name="customerid" size="10" value="" />
<?php echo $customerIDError ?>
</td>
<td style="color:red"></td>
</table>
<p>
<input type="submit" name="submit" value="Save Data" id="submit" />
<input type="reset" value="Reset Form" />
</p>
</tr>
</form>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>" id="custinfo1" style="display:none">
<table>
<tr>
<td>
<label for="username">Username:</label>
</td>
<td>
<input type="text" id="username" name="username" size="10" value="" />
<?php echo $customerIDError ?>
</td>
<td style="color:red"></td>
</table>
<p>
<input type="submit" name="submit" value="Save Data" />
<input type="reset" value="Reset Form" />
</p>
</tr>
</form>
</body>
</html>
check this code
I rectified your code, just run it
<!DOCTYPE html>
<html>
<head>
<title>Prac 2 Task 12</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<style>
#form2{display: none;}
</style>
</head>
<body>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="form1" >
<table>
<tr>
<td><label for="customerid">Customer ID (integer value): </label></td>
<td><input type="text" id="customerid" name="customerid" size="10" value = "<?php echo isset($_POST['customerid']) ? htmlspecialchars($_POST['customerid']):''; ?>" /><?php echo $customerIDError ?></td>
<td style="color:red"></td>
</table>
<p><input type="submit" id="form1submitbtn" name = "submit" value="Save Data"/> <input type="reset" value="Reset Form" /></p>
</tr>
</form>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="form2" >
<table>
<tr>
<td><label for="username">Username: </label></td>
<td><input type="text" id="username" name="username" size="10" value = "<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['customerid']):''; ?>" /><?php echo $customerIDError ?></td>
<td style="color:red"></td>
</table>
<p><input type="submit" name = "submit" value="Save Data"/> <input type="reset" value="Reset Form" /></p>
</tr>
</form>
<script>
$(document).ready(function(){
$("form1submitbtn").click(function(){
$("#form2").show();
});
});
</script>
</body>
</html>

how to insert multiple rows from array values with input

I have my table named i_table with columns:
id name req_qty req_date rcv_qty rec_date
1 metal 1 2014-03-04
2 spring 5 2014-03-04
in my html/php:
<form action="insert.php" method="post">
<?php $resource2=mysql_query("SELECT * FROM i_table",$con);
while($result2=mysql_fetch_array($resource2))
{
?>
<table>
<tr>
<td>
<input type="text" name="id" value="<?php echo $result2['id'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="name" value="<?php echo $result2['name'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="rcv[]" value="" />
</td>
</tr>
<tr>
<td>
<input type="date" name="rcv_date[]" value="" />
</td>
</tr>
</table>
<?php };?>
</form>
how can I insert in multiple arrays from an input according to their unique ID from db? pls help me here... huhu
In your form, add the id as the key -
<form action="insert.php" method="post">
<?php $resource2=mysql_query("SELECT * FROM i_table",$con);
while($result2=mysql_fetch_array($resource2))
{
?>
<table>
<tr>
<td>
<input type="text" name="id[<?php echo $result2['id'];?>]" value="<?php echo $result2['id'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="name[<?php echo $result2['id'];?>]" value="<?php echo $result2['name'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="rcv[<?php echo $result2['id'];?>]" value="" />
</td>
</tr>
<tr>
<td>
<input type="date" name="rcv_date[<?php echo $result2['id'];?>]" value="" />
</td>
</tr>
</table>
<?php };?>
</form>
Then on your insert.php where you post your form, get the id in your foreach -
<?php
if(isset($_POST['id'])){
foreach($_POST['id'] as $id=>$value){
$sql = "UPDATE `i_table` SET `name` = '".$_POST['name'][$id]."', `rcv_qty` = '".$_POST['rcv'][$id]."', `rec_date` = '".$_POST['name'][$id]."' WHERE `id` = ".$id."";
mysql_query($sql,$con);
}
}
?>
note the foreach() is just an example. You will want to sanitize your data before inserting/updating to prevent sql injection. see How can I prevent SQL injection in PHP?

Table Row Sum Within PHP loop

I want to sum table rows dynamically as the user inputs values. Since the number of rows can vary I want to use a php loop to accomplish this. I'm having problems getting the loop to work correctly. If, for example, there are two individual rows to sum only the bottom row will be summed.
<script type="text/javascript">
var sumScoreF = function(a) {
var rowtotal = 0;
n = new Array();
for (i = 1; i <= 3; i++) {
if (parseInt(document.getElementById(a + i).value) > 0) {
n[i] = parseInt(document.getElementById(a + i).value);
rowtotal += n[i];
}
}
document.getElementById(a + 'total').value = rowtotal;
};
</script>
The following is an example of a single row sum. The total column continues to be summed as values are entered. This is a nice effect but not necessary.
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>total</td>
</tr>
<tr>
<td>
<input name="p1g1" id="p1g1" type="text" value="" onChange="sumScoreF('p1g')" />
</td>
<td>
<input name="p1g2" id="p1g2" type="text" value="" onChange="sumScoreF('p1g')" />
</td>
<td>
<input name="p1g3" id="p1g3" type="text" value="" onChange="sumScoreF('p1g')" />
</td>
<td>
<input name="p1gtotal" id="p1gtotal" type="text" value="" />
</td>
</tr>
</table>
Here is my attempt at looping additional rows using php and javascript. The first row will not sum but the second row will. I think the problem is with the javascript variable "m" in that it goes directly to the last row but I can't figure out how to fix it.
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>total</td>
</tr>
<?php for($j=1;$j<=3;$j++) { ?>
<script type="text/javascript">
var k = <?php echo json_encode($j); ?>;
var m = 'p'+k+'g';
</script>
<tr>
<td>
<input name="<?php echo 'p'.$j.'g1'; ?>" id="<?php echo 'p'.$j.'g1'; ?>" type="text" onChange="sumScoreF('m')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g2'; ?>" id="<?php echo 'p'.$j.'g2'; ?>" type="text" onChange="sumScoreF('m')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g3'; ?>" id="<?php echo 'p'.$j.'g3'; ?>" type="text" onChange="sumScoreF('m')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'gtotal'; ?>" id="<?php echo 'p'.$j.'gtotal'; ?>" type="text" />
</td>
</tr>
<?php } ?>
Any help is greatly appreciated. Thanks.
Used PHP to echo the loop variable within the onChange javascript function call:
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>total</td>
</tr>
<?php for($j=1;$j<=3;$j++) { ?>
<tr>
<td>
<input name="<?php echo 'p'.$j.'g1'; ?>" id="<?php echo 'p'.$j.'g1'; ?>" type="text" onChange="sumScoreF('<?php echo 'p'.$j.'g'; ?>')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g2'; ?>" id="<?php echo 'p'.$j.'g2'; ?>" type="text" onChange="sumScoreF('<?php echo 'p'.$j.'g'; ?>')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g3'; ?>" id="<?php echo 'p'.$j.'g3'; ?>" type="text" onChange="sumScoreF('<?php echo 'p'.$j.'g'; ?>')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'gtotal'; ?>" id="<?php echo 'p'.$j.'gtotal'; ?>" type="text" />
</td>
</tr>
<?php } ?>

Categories