hi
i have a table with following columns in it
Code: candidate_id, degree, cgpa, institute
and i have a dynamic form with some javascript in it. the problem in php script i think not in js. this form has two buttons when "need more fields" button and "submit" button. when the user clicks more fields button then three more fields appears. when user fills this form and press submit it it goes to db and insert there. the problem is when user fills as many fields as he wants but only first three fields enters into the db. and remaining of them does not enter. you can pick out what i am doing wrong in the following code.
Code: <script type="text/javascript">
var counter = 0;
//var counter = 0;
//Start a counter. Yes, at 0
function add_phone() {
counter++;
//I find it easier to start the incrementing of the counter here.
var newFields = document.getElementById('add_phone').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
//This will change the 'name' field by adding an auto incrementing number at the end. This is important.
}
var insertHere = document.getElementById('add_phone');
//Inside the getElementById brackets is the name of the div class you will use.
insertHere.parentNode.insertBefore(newFields,insertHere);
}
</script>
<form name="add_a_phone" action="qualificationProcess.php" method="post" enctype="multipart/form-data">
<fieldset>
<div id="phone">
Degree:<input type="text" name="degree_0" value="" />
cgpa:<input type="text" name="cgpa_0" value="" />
institute:<input type="text" name="institute_0" value="" />
</div>
<div id="add_phone" style="display: none;">
Degree:<input type="text" name="degree_" value="" />
cgpa:<input type="text" name="cgpa_" value="" />
institute:<input type="text" name="institute_" value="" />
</div>
<input type="hidden" name="lastId" value="<?php echo $lastId; ?>"/>
<input type="button" id="add_phone()" onclick="add_phone()" value="Give me more fields!" />
<input type="submit" name="submit" value="submit" />
</fieldset>
</form>
<?php
//echo $lastId;
if(isset($_POST['submit']))
//This checks to make sure submit was clicked
{
echo "You clicked submit!
";
echo "Here is your data
";
echo "
";
if ($_POST['cgpa_0'])
//This checks that the proper field has data
{
$continue = FALSE;
$i = 0;
while ($continue == FALSE)
{
if (isset($_POST['degree_'.$i]))
//This looks for an entry after 0 and increments
{
echo $_POST['degree_'.$i] . " = " . $_POST['cgpa_'.$i] . "
";
//Echoing the data
//$id = $_POST['id_'.$i];
$lastId = $_POST['lastId'];
$degree = $_POST['degree_'.$i];
$cgpa = $_POST['cgpa_'.$i];
$institute = $_POST['institute_'.$i];
$db = mysql_connect("localhost");
mysql_select_db("jobolicious", $db);
$query = "INSERT INTO qualification (candidate_id, degree, cgpa, institute) VALUES ('$lastId', '$degree', '$cgpa', '$institute')";
$result = mysql_query($query);
//The four lines above is the example on how the data would be put into a MySQL database. It's not used here
}
else
{
$continue = TRUE;
}
$i++;
}
}
}
?>
and one more thing is in the candidate_id column only one id will be enter. i mean when one user come and fills as many fields as he wants but for those fields this column should have only one id. and also this id is taken from other form through hidden input
Include with Parameters
In a particular page I would like to include a file that requires $_GET parameters.when I go to this sort of url I get what I want.http://www.example.com/test.php?id=1234567890I want the url to be
array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_map() to do the job. Unfortunately, passing an array results in the original, unescaped array being
(sub)screen resize modification doesn't work after ECC 6 EhP 4 installation
Hello,
db entry based on primary key
My "topics" table contains 10 entires*--------------*topicid topic------*--------------* 01 Bye 02 Hi 03 Hello..... 10 Morning*--------------*<?php
How to create a static html menu from a database
Hi,I have built a small cms which allows me to create simple html pages and then upload them to an ftp.Everything is working apart from the menu, I cant get my head round how to create the menu
output_buffering so rewrite
I'm planning to rewrite some of my scripts so they don't have to use output buffering to accomplish their form validation and html displays......so what rules should i follow when rewriting it so i
Confused with Loop
guys, i got confused with Looping...this is the caseI have 3 stocks, let say "Stock A", "Stock B", "Stock C" and the owner of each stock A --> Mr.Jamesstock B
Please help - should be a simple fix.. driving me nuts
Everything seemed to be working fine. I have a table, it alphabetically lists a bunch of cities and relivant city data.However, I found out that the city is showing up only one time when I have can
Hyperlink in PHP to MySQL record
Hello,I am having trouble as i am new to php. I have connected to the database and I have displayed the fields i want on my page. I need to access certain fields by links to each letter.For example A
Bandwidth monitoring?
Hi guys,I need a little information I have written a php app and I occurred to that I need to track the bandwidth that the user is using. I have done a google search and looked through my php books