Hi guys, i have a big problem on these creation. basically if i enter the No of Question then it has to be created No of cells for entering marks.

Eg: No of question = 4 then

quesNO-------Marks
1------------------cell
2------------------cell
3------------------cell
4------------------cell


if anyone of you could help me with this code please!!!!!!!!! hope this would not be too dificult for you guys. Thanks

Recommended Answers

All 6 Replies

Well, how do you want to get the number of question ( pass the value via submitting the form or generating by javascript DOM element without page loading )

You can simply create text field automatically by using 'for loop' in both PHP and Javascript. Some examples:

In PHP:

$question = $x;
for($i=0;$i<$x;$i++){
	echo '--------------------- cell<br />';
}
In Javascript:

var question = x;
for(i=0;i<x;i++){
	document.write('---------------cell<br />');
}

'$x' and 'x' are the variables for the number of questions.

hi dear,
Here is the complete code.

<html>
<head></head><body>
<form method="POST" action="only_check.php">
Enter the number of question
<input type="text" name="question">
<input type="submit">
</form>


<?php
$value=$_POST['question'];

for($i=0;$i<$value;$i++)
{
echo '<input type="text"  style="position:absolute;border:1px #C0C0C0 solid;background-color:#C0FFFF;font-family:Courier New;font-size:13px;"  >'."<br/>";
}

?>
</body></html>

Thanks for your codes. could you please provide the code that once i create two cells (text field)then i have to store in database table the value from the text field. im bit new & stupid with PHP so please bear with me. thanx

hi, here im able to create text field but couldn't insert the data. so could anyone please check this code for me.

<?php 
$value=$_POST['question']; 

for($i=0;$i<$value;$i++) 
{ 
echo "Question NO:"; 
echo '<input type="text" name="qno[]">'."\t"; 

echo "Enter Marks:"; 
echo '<input type="text" name="marks[]">'."\t"; 
echo "<br>"; 
} 
?> 
</form> 
<form name="form1" method="post" action="cellresult.php"> 
  <label> 
  <input type="submit" name="Submit" value="Submit"> 
  </label> 
</form> 

</body>

cellresult.php

<body> 
<?php 
$con = mysql_connect("localhost","root",""); 
if (!$con) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 

mysql_select_db("test", $con); 

$sql="INSERT INTO cell (QNO,MARKS) 
VALUES 
('$_POST['qno']','$_POST['marks']')"; 

if (!mysql_query($sql,$con)) 
  { 
  die('Error: ' . mysql_error()); 
  } 
echo "1 record added"; 

mysql_close($con) 
?> 
</body>

<?php
$value=$_POST;

for($i=0;$i<$value;$i++)
{
echo "Question NO:";
echo '<input type="text" name="qno[]">'."\t";

echo "Enter Marks:";
echo '<input type="text" name="marks[]">'."\t";
echo "<br>";
}
?>
</form>
<form name="form1" method="post" action="cellresult.php">
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</form>

</body>

Fields are out of the form. Try with this one.

<form name="form1" method="post" action="cellresult.php"> 
<?php
	if(isset($_POST['question'])){
		$value=$_POST['question']; 
		for($i=0;$i<$value;$i++) 
		{ 
		echo "Question NO:"; 
		echo '<input type="text" name="qno[]">'."\t"; 

		echo "Enter Marks:"; 
		echo '<input type="text" name="marks[]">'."\t"; 
		echo "<br>"; 
		}
	}
	else{
		echo "No question.";
	}
?> 
  <input type="submit" name="Submit" value="Submit"> 
</form>

Hi, dear

just tell me your whole query what you want to do, how many fields are there in your table and also their name.

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.