i have a script which i found on the internet. i modify that script according to my needs. what is in that script is there are three form fields with two buttons. one button is "Give me more fields" clicking on this button will give you more fields. and second button is submit so the data goes to server side and will be added to db. the problem is when i click give me more fields it gives me three more fields which is right but when i fill all these fields and click submit button it adds to the db but the data in the first three fields adds in the one row and the other three fields data adds in separate row which is not fine for me. so how can i do this so all the data will be added to only one row.
here is js code
Code: [Select]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('addQualification').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('addQualification');
// Inside the getElementById brackets is the name of the div class you will use.
insertHere.parentNode.insertBefore(newFields,insertHere);
}
here is form
Code: [Select]<form name="addAQualification" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<fieldset>
<div id="phone">
Degree:
<input type="text" name="degree_0" value="" />
CGPA/Grade:
<input type="text" name="cgpa_0" value="" />
Institute:
<input type="text" name="institute_0" value="" />
</div>
<div id="addQualification" style="display: none;">
Degree:
<input type="text" name="degree_" value="" />
CGPA/Grade:
<input type="text" name="cgpa_" value="" />
Institute:
<input type="text" name="institute_" value="" />
</div>
<input type="button" id="add_phone()" onclick="add_phone()" value="Give me more fields!" />
<input type="submit" name="submit" value="submit" />
</fieldset>
</form>and here is php
Code: [Select]<?php
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
$degree1 = $_POST['degree_'.$i];
$cgpa1 = $_POST['cgpa_'.$i];
$institute1 = $_POST['institute_'.$i];
$db = mysql_connect("localhost");
mysql_select_db("test", $db);
$query = "INSERT INTO cv
(
degree1,
cgpa1,
institute1
)
VALUES
(
'$degree1',
'$cgpa1',
'$institute1'
)";
$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++;
}
}
}
?>
Cursor statement failed with errors
Following statement failed with the errors.
Loops and Classes
I am making a template system and everything seems to be going well up until I have to loop in a variable where things starts to go weird. I need ideas on how to solve this.It is not picking up
records between 2 dates
Hello all,
getting rid of quotes in strings
sick of trying to deal with them in multiple ways (entering in and taking from database, echoing, echoing within a text input, etc) so i would just like to get rid of them.turn: bob's houseinto: bobs
Search in the PHP Files
have to search asterisk(*) in the php code of the php files .
Problem with PHP code- simple contact form
Hi Folks, I'm relativily new to PHP; I know HTML and CSS stuff but I have a problem- I have a contact form with PHP code in it- grabbed it from the sitemaster website. Unfortunately my form isn't
Am i doing this wrong?
Im pulling from an Oracle database some info... one of which is a field count_pnums which is a NUMBER type field.Code: <?php$sql_E = "SELECT count_pnums, dist_pnums FROM
problems with script
I made a small script wich exchanges points in my website: <?phpsession_start();include_once"config.php";$username = $_SESSION['username']; if(isset($_POST['exchange'])){$spoints =
Typedef struct vs just struct
Anyone know the rationale for using typedef for structs when a struct is itself a typedef? I have seen this in just about every book I have ever read, never with any explanation, yet I know from
Set Categories
I am creating a submission form for somebody to come in and submit products. These products are separated by brand. How can I get them to display according to the brand?Here is the form code:Code: