facing proble with fieldset

General discussions related to php

Moderators: macek, egami, gesf

Gamers
New php-forum User
New php-forum User
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

facing proble with fieldset

Postby Gamers » Mon Feb 11, 2013 12:42 pm

Hi ,

I am in last phase of my project and here i am facing a very annoying problem the problem is regarding with fieldsets, let me explain the scenario.

I have created a page where user have to enter records for its daily activity, records could be one for more than one records, for this i am using JavaScript and the add button to dynamic generate the new row with its element like textbox, dropdownlist, textarea on the page.

Problem=> After insert more than one row on the page i cant be insert all the row data into the mysql table only the first row first row data is insert rest is not but i want user can able to enter all the rows data. Hope you guys understand my problem.

For this i have created two file
index.php => file which hold javascript function and html tags
validation.php=> for mysql querries and validation.


index.php


Code: Select all

<?php include_once('validation.php'); ?>


<html>
<body>
<head><title>Unix Daily Turnover</title></head>


<script>
window.onload = function ()
{
    document.getElementById("addButton").onclick = cloneFieldSet;
}

var counter = 0;
function cloneFieldSet ()

{
    counter++;
    var theField = document.getElementById("field");
    var theClone = theField.cloneNode(true);
    var elements = theClone.elements;
    for (var el in elements)
    {
            elements[el].name += counter.toString();
    }

    theClone.id += counter.toString();
    theField.form.insertBefore(theClone, this);

}


</script>

<form action="index.php" method="post">


<fieldset id="field">

    <input type="text" name="incident" />
                   
    <select name="sev">
            <option value="none0"></option>
            <option value="sev1">sev 1</option>
            <option value="sev2">sev 2</option>
            <option value="sev3">sev 3</option>
            <option value="sev4">sev 4</option>
    </select>
   
    <select name="status[]">
            <option value="none"></option>
            <option value="sample">sample</option>
            <option value="sample1">sample1</option>
            <option value="sample2">sample2</option>
            <option value="sample3">sample3</option>
            <option value="sample4">sample4</option>
            <option value="sample5">sample5</option>
    </select>
                         
    <textarea rows="2" cols="30" name="description_tic"></textarea>

</fieldset>

<input type="button" value="Add" id="addButton" />
<input type="submit" value="submit" name="submit" />
</form>
</body>

</html>


validation.php

Code: Select all

<?php

date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");


if(isset($_POST['submit']))

{                           
      include("connection.php");

      $incidentid=$_POST['incident'];
      $severity=$_POST['sev'];
      $status =$_POST['status'];
      $description_ticket=$_POST['description_tic'];

      
       if(empty($incidentid))

       {
         echo "<font color=red>";
         echo "<br><b>ERROR : </b><br>";   
         echo "INCIDENT ID IS MISSING";
                   echo "<br> </font>";
      
       }
      
      
       if($severity=="none0")

       {
         echo "<font color=red>";
         echo "<br><b>ERROR : </b><br>";   
         echo "sample value IS MISSING";
                   echo "<br> </font>";
      
       }

       if($status=="none")

       {
         echo "<font color=red>";
         echo "<br><b>ERROR : </b><br>";   
         echo "STATUS IS MISSING";
                   echo "<br> </font>";
      
       }

      
      else

      {
      
         $sql = mysql_query("INSERT INTO turnovers (DATE,INCIDENTID,SEVERITY,STATUS,TICKETDES) VALUES
         ('$date','$incidentid','$severity','$status','$description_ticket')") or die ("Database Connection Error" .mysql_error());
      
         
         if($sql)
               {
            
            echo "<br><b> <font color='green'>Turnover for $date Submitted Successfully</b></font>";
         }
       }
   
}      
?>


Please guys help me , if anyone know how could i solve this scenario i will be thanks .

Regards

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: facing proble with fieldset

Postby seandisanti » Thu Feb 14, 2013 1:51 pm

i think the easiest thing to do would be to actually have 2 inputs; one that shows previously added records, and one for adding a single row. so when they add one, it goes to the list of added, and the second field is blanked waiting for next row. you avoid all kind of issues doing it that way, such as having a query fail because of one bad field in one record out of however many they're trying to submit.


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron