0

I have code written in JavaScript
this a form that dynamically adds row (taken from internet and modernized by JavaScript masters)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title>dinamik sheet</title>
<script>
var i=iteration;
function addrow(){
	var tbl = document.getElementById('sheet');
	var iteration = tbl.rows.length;
	var row=tbl.insertRow(iteration);

	var cellLeft = row.insertCell(0);
	var textNode = document.createTextNode(iteration);
	cellLeft.appendChild(textNode);

	var cellRight = row.insertCell(1);
	var el = document.createElement('input');
	el.type = 'text';
	el.name = 'txtRow'+iteration;
	el.id = 'txtRow'+iteration;
	el.size = 40;
	el.value = '0';
	el.onblur = sum;
	cellRight.appendChild(el);

	var cellRight1 = row.insertCell(2);
	cellRight1.id = 'txtRowe'+iteration;

	var cellRightsel = row.insertCell(3);
	var sel = document.createElement('select');
	sel.name = 'selRow' + iteration;
	sel.id = 'selRow' + iteration;
	sel.onchange = sum;
	sel.options[0] = new Option('MotherBoard ASUS', '150');
	sel.options[1] = new Option('MotherBoard Gigabyte', '165');
	sel.options[2] = new Option('MotherBoard MSI', '100');
	sel.options[3] = new Option('Graphiqcard ASUS', '85');
	sel.options[4] = new Option('GraphigCard ATI', '90');
	sel.options[5] = new Option('GraphigCard GefORCE', '88');
	cellRightsel.appendChild(sel);
	sum();
}
function removeRowFromTable()
{
  var tbl = document.getElementById('sheet');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

function sum(){
	var s1 = 0;
	var s2 = 0;
	var tbl=document.getElementById('sheet');
	var iteration=tbl.rows.length-1;
	for(var i=1; i<=iteration; i++){//loop through table rows
		var el1 = document.getElementById('txtRow'+i);//Row's Income field
		var el2 = document.getElementById('selRow'+i);//Row's percentage menu
		var el3 = document.getElementById('txtRowe'+i);//Row's Tax cell
		if(!el1 || !el2 || !el3) continue;
		var txt = el1.value;
		if(txt != ( '' + Number(txt) )) continue;//reject non-numeric entries
		var tax = Number(txt) * Number(el2[el2.selectedIndex].value);
		el3.innerHTML = tax.toFixed(2);
		s1 += Number(txt);
		s2 += tax;
	}
	var t1 = document.getElementById('total');
	var t2 = document.getElementById('taxtotal');
	if(t1){ t1.value = s1.toFixed(2); }
	if(t2){ t2.value = s2.toFixed(2); }
}

onload = function(){
	addrow();
}
</script>
</head>
<body>
<form name="eval_edit" method="POST" action="part.php?id=iteration-1>
<table align="center" width="75%">
<tr>
<td align="center">Balance sheet</td></tr>
<tr>
<td align="center">
	<table id="sheet" border="1">
	<tr><td>object</td><td>amount of products</td><td>amount of price per saled product </td><td>part name</td></tr>

	</table>
</td>
</tr>
<tr>
<td align="center">
<input type="button" value="Add" onclick="addrow()" />
<input type="button" value="Remove" onclick="removeRowFromTable()" />
<input type="button" value="SUM" onClick="sum()"/>
<input type="submit" value="Submit" /><br />
</td>
</tr>
<tr>
<td align="left">
<input id="total" name="total" type="text"/>total amount of products<br />
<input id="taxtotal" name="taxtotal" type="text"/>total price of products
</td>
</tr>
</table>
</form>

</body>
</html>

and i created
table in PHPmyadmin
teze.sql

CREATE TABLE `teze` (
  id int(11) NOT NULL auto_increment,
  amount varchar(200) NOT NULL default '',
  price varchar(100) NOT NULL default '',
  date date NOT NULL default '0000-00-00',
  name text NOT NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

and part.php

<?php
@$db=mysql_connect('localhost','user DB','password DB');
mysql_select_db('database name');
if (isset($_POST['submit']))
{
$amount=$_POST['amount'];
$price=$_POST['amount'];
$date=$_POST['amount'];
$name=$_POST['amount'];
$i=($_GET['id'])
for($l=1;$l<$i;$l++){
$sql="INSERT INTO 'teze' VALUES ('','".$amount."','".$price."','".$date."','".$name."')";
$result=mysql_query($sql);
}
}
?>

but it gives error
I would like to add rows with help JavaScript
and submit data into mysql database with help of PHP
but it returns error
I need this script immediatly
if possible please help me
thanks beforehands

Edited by azegurb: n/a

2
Contributors
38
Replies
39
Views
7 Years
Discussion Span
Last Post by azegurb
Featured Replies
  • [QUOTE=azegurb;1132555]thank you is that form true that I created? arent there any errors or the other coding is true?[/QUOTE] What is the other coding, the form and data sending will work fine from your coding, also I think you are adding the products costs and products in your scripts, the … Read More

0

Check your code... You missed out
$l++ in for loop
and semicolon at the end of $i variable.

use the following code

$i=($_GET['id']);
	for($l=1;$l<$i;$l++){
		$sql="INSERT INTO 'teze' VALUES ('','".$amount."','".$price."','".$date."','".$name."')";
		$result=mysql_query($sql);
	}

Edited by saiprem: n/a

0

thank you
is that form true that I created?
arent there any errors
or the other coding is true?

1

thank you
is that form true that I created?
arent there any errors
or the other coding is true?

What is the other coding, the form and data sending will work fine from your coding, also I think you are adding the products costs and products in your scripts, the remove button script removeRowFromTable() function will not update the price, check that and fix that as well..

The remaining everything looks fine, and it will works...

Edited by saiprem: n/a

0

i tried but i got nothink
can anyone help me?

You tried replacing the code which I gave to you in my previous post...

Replace part.php around 10th line.... with the following code and let me know.. what the error you are getting

$i=($_GET['id']);
	for($l=1;$l<$i;$l++){
		$sql="INSERT INTO 'teze' VALUES ('','".$amount."','".$price."','".$date."','".$name."')";
		$result=mysql_query($sql);
	}

Edited by saiprem: n/a

0

there are another errors which i dont see

send me the those another errors, If you are unable to view those errors, then add the following function in the top of the page.

<?php ini_set('display_errors',1); ?>

Edited by saiprem: n/a

0

Okay, I found another error in your form

You haven't closed the form properly.........
try replace the

try with the following line....

<form name="eval_edit" method="POST" action="exe.php?id=iteration-1">

0

you know
if you want enter aziko.6te.net/tet/azer.html
you will see dynamic table when i add data with submit button
it opens blank part.php page there are not any errors for viewing
i guess i have error how to receive data from html table
for ex: when i click add button it adds rows and select options
automatically each added text row has name texRow+iteration
i need how to receive this name or id using PHP POST or GET method
thank you for attention

0

i tried but again it returns nothink
i see phpmyadmin table its empty

0

you know
if you want enter aziko.6te.net/tet/azer.html
you will see dynamic table when i add data with submit button
it opens blank part.php page there are not any errors for viewing
i guess i have error how to receive data from html table
for ex: when i click add button it adds rows and select options
automatically each added text row has name texRow+iteration
i need how to receive this name or id using PHP POST or GET method
thank you for attention

Dear azegurb,

Replace your part.php with the following code, and check it.... Still you are getting the same error or you are able to view the post details

<?php
ini_set('display_errors',1);
echo "<pre>";
print_r($_POST);
echo "</pre>";
exit;
?>
0

Check your post data, In your post data, you are not getting the variable 'amount', so how can you call $_POST in your script....

0

it returned

Array
(
    [txtRow1] => 23
    [selRow1] => 150
    [txtRow2] => 23
    [selRow2] => 150
    [total] => 46.00
    [taxtotal] => 6900.00
)
0

thank you
can you help me to build up part.php if possible
if i dont disturb you

0

thank you
can you help me to build up part.php if possible
if i dont disturb you

How would I know what are all the fields you need to insert in your database, Collect the post data and try inserting the required data into your database.

0

simply i need how to build loop for ex txtRow+i or how i dont know
if possible i very please help me
thanks

0

Add a hidden input box in your form as

<input type="hidden" name="count_rows" id="count_rows" />

and in your addrow() function add a line below

iteration

as shown in the below...

var iteration = tbl.rows.length;

document.getElementById('count_rows').value = iteration;

Now after posting your data you will also get the count of rows......
and try inserting the data using for loop 
such as  variable < $_POST['count_rows']

I think you got what am saying....

0

i need how to see amount of price per saled product and part name section
it shows object and amount of products product, totalsum

0

i need how to see amount of price per saled product and part name section
it shows object and amount of products product, totalsum

To read the value of amount of price per saled product

You need to create this value also as Textbox, as you did for "amount of products", then you can read that value also in the post.

Coming to part name , the values are getting for it in the selRow1, selRow2....

0

i did as you said you can enter aziko.6te.net/tet/azer.html
i build up
part.php
as show below

<?php
@$db=mysql_connect('localhost','238147','19841223');
mysql_select_db('database name');
if (isset($_POST['submit']))
{
$amount=$_POST['txtRow+i'];
$price=$_POST['selRow+i'];
$date=$_POST['2010-12-12'];
$name=$_POST['textRowe1'];
$i==($_GET['count_rows']);
for($l=1;$l<$i;$l++){
$sql="INSERT INTO 'teze' VALUES ('','".$amount."','".$price."','".$date."','".$name."')";
$result=mysql_query($sql);
if($result){

echo "data entered";
}
else {

echo "data not entered";
}
}
?>

but it returned error like that

Parse error: syntax error, unexpected $end in /home/vhosts/aziko.6te.net/tet/part1.php on line 23
0

i did as you said you can enter aziko.6te.net/tet/azer.html
i build up
part.php
as show below

<?php
@$db=mysql_connect('localhost','238147','19841223');
mysql_select_db('database name');
if (isset($_POST['submit']))
{
$amount=$_POST['txtRow+i'];
$price=$_POST['selRow+i'];
$date=$_POST['2010-12-12'];
$name=$_POST['textRowe1'];
$i==($_GET['count_rows']);
for($l=1;$l<$i;$l++){
$sql="INSERT INTO 'teze' VALUES ('','".$amount."','".$price."','".$date."','".$name."')";
$result=mysql_query($sql);
if($result){

echo "data entered";
}
else {

echo "data not entered";
}
}
?>

but it returned error like that

Parse error: syntax error, unexpected $end in /home/vhosts/aziko.6te.net/tet/part1.php on line 23

There may be some closing brackets missing in it check it, I can tell you immediately, but if you go through the code, you will understand your code and what you are doing mistakes....Read the error and try to solve it....

Edited by saiprem: n/a

0

i read it the 23 row is last row
it is

?>

it seems to me it is true
what do you think (you helped me today much)

0

i read it the 23 row is last row
it is

?>

it seems to me it is true
what do you think (you helped me today much)

You are right, you missed out closing brace of for loop, but your code will not work...Try to implement the following code..

<?php
@$db=mysql_connect('localhost','238147','19841223');
mysql_select_db('database name');
$i = $_POST['count_rows'];
	//echo $i;
	for($l=1;$l<=$i;$l++)
	{
		$amount = $_POST["txtRow$l"];
		
		$price = $_POST["selRow$l"];
		$date = '2010-12-12';
		$name = $_POST["textRowe$l"];

		$sql="INSERT INTO teze (`id` ,`amount` ,`price` ,`date` ,`name`) VALUES (NULL,'".$amount."','".$price."','".$date."','".$name."')"; 
		$result=mysql_query($sql);
		
		if($result)
		{
			echo "data entered";
		}
		else
		{
			echo "data not entered";
		}
	}

?>

Edited by saiprem: n/a

0

i did it but it returned blank page no errors

and then i looked at teze table using phpmyadmin
there are not any entry so table is empty?
no data inserted

0

i did it but it returned blank page no errors

and then i looked at teze table using phpmyadmin
there are not any entry so table is empty?
no data inserted

In my previous post I have edited the code, copy it and re try.....
Good Luck........

Edited by saiprem: n/a

0

i did as you said but the same result

copy the entire source again from previous post and recheck, It is working for me in my local environment...... Or paste your code again in forum, I will check where is the mistake...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.