Hi, i m the beginner for php.What happen to my coding ~ it cannot work~~

require_once('../../../Connections/admin_db.php'); 


$submit = $_POST['Submit'] ;
	if ($submit == 'Submit')
	
{
		
		
		$ag = $_POST['ag'];
		
		
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO user(`age`)
				VALUES ('$ag') " ; 
				
		mysql_query($q) or die(mysql_error()) ;
		if (!mysql_error())
			echo "<div align=center class=alert3>Instructor '$ag - $ag' Registration SUCCESS!!!</div>
					<script type=\"text/javascript\">alert(\"Instructor '$ag - $ag' Registration SUCCESS!!!\") ;</script>";		
			
	}
Member Avatar for diafol
$submit = $_POST['Submit'] ;
	if ($submit == 'Submit')

Try

if(isset($_POST['Submit') && $_POST['Submit'] == "Submit"){

sir~ still cannot work

this my complete coding~~

<table width="376" border="2" cellspacing="2" cellpadding="2">
  <tr>
    <td width="141">age</td>
    <td width="213"><form action="" method="post" name="Submit" id="Submit">
      <label>
        <input type="text" name="ag" id="ag">
      </label>
    </form></td>
  </tr>
</table>
<form name="form3" method="post" action="">
  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p>&nbsp;</p>
<?php 
require_once ('../../../Connections/admin_db.php'); 


if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {

		
		$ag = $_POST['ag'];
		
		
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO user(age)
				VALUES ('$ag') " ; 
				
		mysql_query($q) or die(mysql_error()) ;
		
	}

		
	
?>

this my complete coding~~

<table width="376" border="2" cellspacing="2" cellpadding="2">
  <tr>
    <td width="141">age</td>
    <td width="213"><form action="" method="post" name="Submit" id="Submit">
      <label>
        <input type="text" name="ag" id="ag">
      </label>
    </form></td>
  </tr>
</table>
<form name="form3" method="post" action="">
  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p>&nbsp;</p>
<?php 
require_once ('../../../Connections/admin_db.php'); 


if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {

		
		$ag = $_POST['ag'];
		
		
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO user(age)
				VALUES ('$ag') " ; 
				
		mysql_query($q) or die(mysql_error()) ;
		
	}

		
	
?>

You're closing the first form without a submit. You're submitting the second form with no inputs.

Try:

<table width="376" border="2" cellspacing="2" cellpadding="2">
  <tr>
    <td width="141">age</td>
    <td width="213"><form name="form3" method="post" action="">
      <label>
        <input type="text" name="ag" id="ag">
      </label>
    </td>
  </tr>
</table>

  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p>&nbsp;</p>
<?php 
require_once ('../../../Connections/admin_db.php'); 


if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {

		
		$ag = $_POST['ag'];
		
		
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO user(age)
				VALUES ('$ag') " ; 
				
		mysql_query($q) or die(mysql_error()) ;
		
	}

		
	
?>
Member Avatar for diafol

No wonder it doesn't work, your HTML is mashed to hell. You have the same id for more than one element. You don't seem to have a submit form for the first form. Why have you got 2 forms anyway?

Listen, sort out your HTML before attempting php.

thanks you~ It work!

i have the another problem ...

i have create a table( write in javascript) which can add row when click the button, but after that how combine it with php code which i can insert data into database?

<HTML>
<HEAD>
    <TITLE>PLO Performance Criteria</TITLE>
    <SCRIPT language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            cell1.appendChild(element1);
 
            var cell2 = row.insertCell(1);
            cell2.innerHTML = rowCount + 1;
 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell3.appendChild(element2);
			
			var cell4 = row.insertCell(3);
            var element3 = document.createElement("input");
            element3.type = "text";
            cell4.appendChild(element3);
			
			var cell5 = row.insertCell(4);
            var element4 = document.createElement("input");
            element4.type = "text";
            cell5.appendChild(element4);
			
			var cell6 = row.insertCell(5);
            var element5 = document.createElement("input");
            element5.type = "text";
            cell6.appendChild(element5);
		 
 
        }
 
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
 
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }
 
            }
            }catch(e) {
                alert(e);
            }
        }
 
    </SCRIPT>
</HEAD>
<BODY>
    <TABLE width="403" height="34" border="1" align="left" id="dataTable">
      <TR>
            <TD width="46"><INPUT type="checkbox" name="chk"/></TD>
            <TD width="33"> 1 </TD>
            <TD width="151" id="dataTable"><input type="text" id="cr" /></TD>
            <TD width="145" id="dataTable"><input name="level" type="text" id="level" /></TD>
            <TD width="145" id="dataTable"><input name="level_desc" type="text" id="level_desc" /></TD>
            <TD width="145" id="dataTable"><input name="pc_desc" type="text" id="pc_desc" /></TD>
            
        </TR>
    </TABLE>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>
      <input type="button" value="Add Row" onClick="addRow('dataTable')" />
      <input type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
      
    </p>
</BODY>
</HTML>

yes you can do it.....
i too made a similar program earlier....
for that the name u r assiging to each field must be an array and then just for each array element u can do any operation.....
instead of this :-

<TD width="46"><INPUT type="checkbox" name="chk"/></TD>
            <TD width="33"> 1 </TD>
            <TD width="151" id="dataTable"><input type="text" id="cr" /></TD>
            <TD width="145" id="dataTable"><input name="level" type="text" id="level" /></TD>
            <TD width="145" id="dataTable"><input name="level_desc" type="text" id="level_desc" /></TD>
            <TD width="145" id="dataTable"><input name="pc_desc" type="text" id="pc_desc" /></TD>

do this:-

<TD width="46"><INPUT type="checkbox" name="chk[]"/></TD>
            <TD width="33"> 1 </TD>
            <TD width="151" id="dataTable"><input type="text" name="abc[]" id="cr" /></TD>
            <TD width="145" id="dataTable"><input name="level[]" type="text" id="level" /></TD>
            <TD width="145" id="dataTable"><input name="level_desc[]" type="text" id="level_desc" /></TD>
            <TD width="145" id="dataTable"><input name="pc_desc[]" type="text" id="pc_desc" /></TD>

and use form to submit data and on next page just using$_POST u can get the data submitted.....

Hope it is useful and clear...
IF UR DOUBT IS CLEARED MARK THIS THREAD AS SOLVED

hi,tomato.pgn
I have try it but it cannot insert into database ~ can help me check the coding~ thnks

<HTML>
<HEAD>
    <TITLE>PLO Performance Criteria</TITLE>
    <SCRIPT language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            cell1.appendChild(element1);
 
            var cell2 = row.insertCell(1);
            cell2.innerHTML = rowCount + 1;
 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell3.appendChild(element2);
			
			var cell4 = row.insertCell(3);
            var element3 = document.createElement("input");
            element3.type = "text";
            cell4.appendChild(element3);
			
			var cell5 = row.insertCell(4);
            var element4 = document.createElement("input");
            element4.type = "text";
            cell5.appendChild(element4);
			
			var cell6 = row.insertCell(5);
            var element5 = document.createElement("input");
            element5.type = "text";
            cell6.appendChild(element5);
		 
 
        }
 
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
 
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }
 
            }
            }catch(e) {
                alert(e);
            }
        }
 
    </SCRIPT>
</HEAD>
<BODY>
    <TABLE width="403" height="34" border="1" align="left" id="dataTable">
    <TD width="46"><INPUT type="checkbox" name="chk[]"/></TD>
            <TD width="33"> 1 </TD>
            <TD width="151" id="dataTable"><input type="text" name="abc[]" id="cr" /></TD>
            <TD width="145" id="dataTable"><input name="level[]" type="text" id="level" /></TD>
            <TD width="145" id="dataTable"><input name="level_desc[]" type="text" id="level_desc" /></TD>
            <TD width="145" id="dataTable"><input name="pc_desc[]" type="text" id="pc_desc" /></TD>
    </TABLE>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form name="form1" method="post" action="">
  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit">
  </label>
  <input type="button" value="Add Row" onClick="addRow('dataTable')" />
  <input type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
</form>
<p>&nbsp; </p>
<p>&nbsp;</p>
</BODY>
</HTML>

<?php 
require_once ('../../../Connections/admin_db.php'); 

mysql_select_db("admin_db");



if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {

		
		$abc          = $_POST['abc[]'];
		$level        = $_POST['level[]'];
		$level_desc   = $_POST['level_desc[]'];
		$pc_desc      = $_POST['pc_desc[]'];
		
		
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO plo_pc(plo_criteria,plo_level,level_dec,plo_desc)
				VALUES ('$abc','$level','$level_desc','$pc_desc') " ; 
				
		mysql_query($q) or die(mysql_error()) ;
		
	}

		
	
?>

see th point is that u must write all control fields that u want to POST in another page inside <form> tag....
and more over u have to insert the code for each element of array....

<form name="form1" method="post" action="">
<TD width="46"><INPUT type="checkbox" name="chk[]"/></TD>
            <TD width="33"> 1 </TD>
            <TD width="151" id="dataTable"><input type="text" name="abc[]" id="cr" /></TD>
            <TD width="145" id="dataTable"><input name="level[]" type="text" id="level" /></TD>
            <TD width="145" id="dataTable"><input name="level_desc[]" type="text" id="level_desc" /></TD>
            <TD width="145" id="dataTable"><input name="pc_desc[]" type="text" id="pc_desc" /></TD>
 <label>
    <input type="submit" name="Submit" id="Submit" value="Submit">
  </label>
</form>

and to receive data write this.....

if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {
$i=0;
foreach($_POST['abc'] as $value )
{
                $abc          = $value;
		$level        = $_POST['level'][$i];
		$level_desc   = $_POST['level_desc'][$i];
		$pc_desc      = $_POST['pc_desc'][$i];
 
 
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO plo_pc(plo_criteria,plo_level,level_dec,plo_desc)
				VALUES ('$abc','$level','$level_desc','$pc_desc') " ; 
 
		mysql_query($q) or die(mysql_error()) ;
$i=$i+1;
}
}

I haven't tested this one for now....but will work fine...
If any problem persist then PM me any time....
If ur doubt is clear then mark this thread read and notify me whether my post was helpful or not....

Tomato~thx for your reply~it is work ~

but it still have a little problem
i want to make it insert all the data together but not the user insert one by one .

i already post this on other thread, hope this will help you
here's how to get an array input element value

$x = array();
for($i=0;$i<$count;$i++){
$x[$i]['abc'] = $_POST['abc'][$i];
$x[$i]['level'] = $_POST['level'][$i];
$x[$i]['level_desc'] = $_POST['level_desc'][$i];
$x[$i]['pc_desc'] = $_POST['pc_desc'][$i];
$q = "INSERT INTO plo_pc(plo_criteria,plo_level,level_dec,plo_desc) values
('".$x[$i]['abc']."','".$x[$i]['level']."','"..$x[$i]['level_desc']"',
'".$x[$i]['pc_desc']."') " ; 
mysql_query($q) or die(mysql_error()) ;
}
//by the way add $_SERVER['PHP_SELF'] on form
//e.g
action="<? $_SERVER['PHP_SELF'] ?>"
$_SERVER['PHP_SELF']

can explain to me it is for what? thx~

if i add

$_SERVER['PHP_SELF']

it show access horbidden

Their is something wrong in ur code....wait i will design a new one for u ....and then post it here

Thx ~ tomato~for your help

just look at my example....i will come with a solution later...
abc.php

<html>
<head>
<title>Add text
</title>
</head>
<script type="text/javascript">
function add_field(){
	var max = 4; // total number of fields
	var cont = document.getElementById('addhere'); // refer to the div
	var numfields = cont.getElementsByTagName("input").length; // get number of input fields in the div
	if(numfields < max){
		// create a div element
		var div1 = document.createElement('div');
		// Get template data
		div1.innerHTML = document.getElementById('fieldtpl').innerHTML;
		// append to div, so that template data becomes part of document
		document.getElementById('addhere').appendChild(div1);
	}
}
</script>

<form method="post" action="formaction.php" enctype="multipart/form-data" >
    <div id="addhere">
		<input type="file" name="upload[]" value="" size="50" onchange="add_field();" >
	</div>
	<input type="submit">
</form>
<!-- Template. This whole data will be added directly to working div above -->  
<div id="fieldtpl" style="display:none">
	<input type="file" name="upload[]" value="" size="50" onchange="add_field();" >
</div>
<//body>

formaction.php

<?php
$i=0;

foreach($_POST['upload'] as $value )
{echo "<table border='1'><tr><td>";
echo $i+1;
echo "</td><td>".$value."</td><td>".$_POST['ans'][$i]."</td></tr></table><br/>";
$i++;
}
?>

is the one i posted not working????

no~ the example u run can post ~but i still cannot get it ~

ohh sorry..by mistake i posted different one....
it's the working one.....
abc.php

<html>
<head>
<title>Add text
</title>
</head>
<script type="text/javascript">
function add_field(a){
	
		// create a div element
		var div1 = document.createElement('div');
		// Get template data
		if(a==1){
		div1.innerHTML = document.getElementById('fieldtpl').innerHTML;
}
		// append to div, so that template data becomes part of document
		document.getElementById('addhere').appendChild(div1);

	
}
</script>
<?php
$i=0;
?>
<form method="post" action="formaction.php" enctype="multipart/form-data" >
    <div id="addhere">

q		<input type="text" name="upload[]" value="" size="30" ><br/>
&nbsp;&nbsp;	<input type="text" name="ans[]" value="" size="30" ><br/><br/>
</div>

&nbsp;&nbsp;&nbsp;<input type ="button" value="add more" onclick="add_field(1);">
<input type ="button" value="add textarea" onclick="add_field(2);">	
<input type="submit">

</form>
<!-- Template. This whole data will be added directly to working div above -->  
<div id="fieldtpl" style="display:none">
q		<input type="text" name="upload[]" value="" size="30" ><br/>
&nbsp;&nbsp;	<input type="text" name="ans[]" value="" size="30" ><br/><br/>

</div>
</body>
</html>

formaction.php

<?php
$i=0;

foreach($_POST['upload'] as $value )
{echo "<table border='1'><tr><td>";
echo $i+1;
echo "</td><td>".$value."</td><td>".$_POST['ans'][$i]."</td></tr></table><br/>";
$i++;
}
?>

Hope it's useful...if it helped u...add reputation...
and mark the thread as solved....

hi,tomato~ can you help me to correct my coding? because my problem facing is it is only insert the data in the first row into database,the data in 2nd row cannot insert together with the first row .so ,it is the problem that i cannot solved it.

<SCRIPT language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            cell1.appendChild(element1);
 
          
            var cell2 = row.insertCell(1);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell2.appendChild(element2);
			
			var cell3 = row.insertCell(2);
            var element3 = document.createElement("input");
            element3.type = "text";
            cell3.appendChild(element3);
			
			var cell4 = row.insertCell(3);
            var element4 = document.createElement("input");
            element4.type = "text";
            cell4.appendChild(element4);
			
			var cell5 = row.insertCell(4);
            var element5 = document.createElement("input");
            element5.type = "text";
            cell5.appendChild(element5);
		 
 
        }
 
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
 
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }
 
            }
            }
			catch(e) {
                alert(e);
            }
        }

php

<?php 
require_once ('../../../Connections/admin_db.php'); 

mysql_select_db("admin_db");

if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {
$i=0;
foreach($_POST['abc'] as $value )
{
                $abc           = $_POST['abc'][$i];
		$level         = $_POST['level'][$i];
		$level_desc    = $_POST['level_desc'][$i];
		$pc_desc       = $_POST['pc_desc'][$i];
 
 
		//Insert Data into Instructor Profile Info		
		$q = "INSERT INTO plo_pc(p_name,plo_id,plo_criteria,plo_level,level_dec,plo_desc)
				VALUES ('$list','$plo_id','$abc','$level','$level_desc','$pc_desc') " ; 
 
		mysql_query($q) or die(mysql_error()) ;
$i=$i+1;
}
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.