form:

<form>
    <table>
        <tr>
            <th>Subject</th>
            <th>Description</th>
            <th>Final Grade</th>
            <th>Remarks</th>
        </tr>
        <!--
            You can loop this one, depends on the subjects.
            Subject must not be encoded. Baka lalagyan ng maling subject.
            I just base it to your design so naging ganito.
        -->
        <tr>
            <td><input type="text" name="grades[][subject]" id="grades[][subject]" value="" /></td>
            <td><input type="text" name="grades[][description]" id="grades[][description]" value="" /></td>
            <td><input type="text" name="grades[][grade]" id="grades[][grade]" value="" /></td>
            <td><input type="text" name="grades[][remark]" id="grades[][remark]" value="" /></td>
        </tr>
        <tr>
            <td><input type="text" name="grades[][subject]" id="grades[][subject]" value="" /></td>
            <td><input type="text" name="grades[][description]" id="grades[][description]" value="" /></td>
            <td><input type="text" name="grades[][grade]" id="grades[][grade]" value="" /></td>
            <td><input type="text" name="grades[][remark]" id="grades[][remark]" value="" /></td>
        </tr>
        <tr>
            <td><input type="text" name="grades[][subject]" id="grades[][subject]" value="" /></td>
            <td><input type="text" name="grades[][description]" id="grades[][description]" value="" /></td>
            <td><input type="text" name="grades[][grade]" id="grades[][grade]" value="" /></td>
            <td><input type="text" name="grades[][remark]" id="grades[][remark]" value="" /></td>
        </tr>
    </table>
</form>

then this is my summary of insert.php

 $course        = $_POST["course"];
    $semester    = $_POST["semester"];
    $year        = $_POST["year"];
    $id_no        = $_POST["id_no"];
    $result        = $_POST["grades"];

    if (count($result > 0))
    {
        $new = array();

        foreach ($result as $key => $value)
        {
            $new[] = "('" . $course . "', '" . $semester . "', '" . $year . "', '" . $id_no . "', '" . $value["subject"] . "', '" . $value["description"] . "', '" . $value["grade"] . "', '" . $value["remark"] . "')";
        }

        if (count($new) > 0)
        {
            $query = mysql_query("INSERT INTO grades (course, semester, year, id_no, subject, descriptive_title, final_grades, remarks) VALUES " . implode(", ", $new)");   <----this is line 32

            if ($query)
            {
                echo "SUCCESS";
            }
            else
            {
                echo "FAILED";
            }
        }
    }

showing error on line 32:

Parse error: syntax error, unexpected '"' in C:\AppServ\www\sample admin\my-admin\insert_grades.php on line 32

thank you..:}hope you understand..:}

cause my codes is not working..

Recommended Answers

All 6 Replies

Change this: implode(", ", $new) to single quotes: implode(', ', $new) bye!

yeah,,,nice,,,it works now..:}thx cereal

 for($a=0; $a<$strcount; $a++)
 {
     echo $strstudent[$a]=$_POST['studentid'];
     echo $strfa1[$a]=$_POST['fa1'];
     echo $strfa2[$a]=$_POST['fa2'];
     echo $strsa1[$a]=$_POST['sa1'];
     echo $strfa3[$a]=$_POST['fa3'];
     echo $strfa4[$a]=$_POST['fa4'];
     echo $strsa2[$a]=$_POST['sa2'];
     echo $sqlmarks="insert into marks_master(student_id,fa1_exam,fa2_exam,sa1_exam,fa3_exam,fa4_exam,sa2_exam,entry_date) 
                values('$strstudent[$a]','$strfa1[$a]','$strfa2[$a]','$strsa1[$a]','$strfa3[$a]','$strfa4[$a]','$strsa2[$a]',curdate())";
$rowmarks=mysql_query($sqlmarks);
 }

<tr>
<!-- INSERT_MARK.php -- >

                        <td><?php echo $i;?>
                        <tr>
                        <td><?php echo $i;?></td>
                        <td>   <?php echo $resstudent['gr_no']; ?> <br /></td>
                        <td>   <?php echo $resstudent['student_name']; ?> <br /></td>
                        <input type="hidden" name="sl_no" value="<?php echo $i;?>" />
                        <input type="hidden" name="studentid" value="<?php echo $resstudent['stu_id']; ?>"/><!-- Each Students ID (Hidden Value)-->
                        <td><input style="width:50px;" name="fa1" type="text" /></td>
                        <td><input style="width:50px;" name="fa2" type="text" /></td>
                        <td><input style="width:50px;" name="sa1" type="text" /></td>
                        <td><input style="width:50px;" name="fa3" type="text" /></td>
                        <td><input style="width:50px;" name="fa4" type="text" /></td>
                        <td><input style="width:50px;" name="sa2" type="text" /></td>
                        <?php }?>
                    </tr>
                        </td>


                    <td>   <?php echo $resstudent['gr_no']; ?> <br /></td>
                    <td>   <?php echo $resstudent['student_name']; ?> <br /></td>
                    <input type="hidden" name="sl_no" value="<?php echo $i;?>" />
                    <input type="hidden" name="studentid" value="<?php echo $resstudent['stu_id']; ?>"/><!-- Each Students ID (Hidden Value)-->
                    <td><input style="width:50px;" name="fa1" type="text" /></td>
                    <td><input style="width:50px;" name="fa2" type="text" /></td>
                    <td><input style="width:50px;" name="sa1" type="text" /></td>
                    <td><input style="width:50px;" name="fa3" type="text" /></td>
                    <td><input style="width:50px;" name="fa4" type="text" /></td>
                    <td><input style="width:50px;" name="sa2" type="text" /></td>
                    <?php }?>
                </tr>
I am unable to save this in my database please check the values in query is coming but not save in database, please help and suggest me.

CREATE TABLE IF NOT EXISTS `tbl_questionanswer` (
  `aqid` int(11) NOT NULL AUTO_INCREMENT,
  `qid` int(11) NOT NULL,
  `answer` varchar(500) NOT NULL,
  `collaborator` varchar(25) NOT NULL,
  `interviewdate` date NOT NULL,
  PRIMARY KEY (`aqid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_questions`
--

CREATE TABLE IF NOT EXISTS `tbl_questions` (
  `questionid` int(11) NOT NULL AUTO_INCREMENT,
  `questions` text NOT NULL,
  PRIMARY KEY (`questionid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `tbl_questions`
--

INSERT INTO `tbl_questions` (`questionid`, `questions`) VALUES
(1, '<p>What are the aspects that at this moment in your work role?</p><br/>\r\n<p>What are areas for improvement?</p><br/><p>\r\nOf all the aspects that you have given me, in this moment which is the priority for you?\r\n<p>What would you improve in the short term?</p>'),
(2, '<p>What are difficulties exactly?</p><p>You make me some examples of when things work? And when / where they do not work?</p><br/>\r\n<p>You exactly how did you react? What consequences have sprung?</p>'),
(3, '<p>What might help you improve in this aspect?</p><br/>\r\n<p>What do you notice that your colleagues do in similar situations?</p><br/><p>\r\nIf I can add other ideas, I can think of ... (add any suggestions)</p>\r\n'),
(4, '<p>Considering your agenda and the moments that we have available, what actions you will do ?</p><br/>\r\n<p>(Drawing up a shared action plan)</p><br/>\r\n<p>\r\nQuando ci rivediamo per un follow up?</p><br/>\r\n<p>\r\nWhen I see you for a follow-up?</p><br/>\r\n');

-----------------------------------------------------------------
<?php if($_POST["Submit"]=="Submit")
{ $checkbox1 = $_POST['qid'];
$checkbox2 = $_POST['answer'];
$collaborator = $_POST['collaborator'];
$date = $_POST['date'];  
//print_r($_POST);
//print_r($checkbox1); die();
    /* for ($i=0; $i<sizeof($checkbox1);$i++) {
    echo $query="INSERT INTO tbl_questionanswer (qid,answer,collaborator,date) VALUES ('".$checkbox1[$i]."', '".$checkbox2[$i]."', '".$collaborator."', '".$date."')"; die();
    mysql_query($query) or die ('Error updating database');
    echo "Record is inserted.";
   } */
 echo $query = "INSERT INTO tbl_questionanswer (qid,answer,collaborator,date) values  "; 

    for($i=0; $i<count($checkbox1);$i++) {
             $question = $checkbox1[$i];
             $answer = $checkbox2[$i]; 
             $collaborator = $_POST['collaborator'];
$date = $_POST['date'];
             $query .= "('$question', '$answer', '$collaborator', '$date'),"; 
   }
              $query = rtrim($query,',');
              echo $query; 
         mysql_query($query);
         //or die ('Error updating database'); 
         } ?>
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.