Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:03:16+00:00 2026-06-17T04:03:16+00:00

Hey guys, I’m having trouble in inserting my values into MySQL using PHP and

  • 0

Hey guys, I’m having trouble in inserting my values into MySQL using PHP and Ajax. I’m trying to insert into MySQL with single button with multiple input.

JS:

 $('#save_grade_button').click(function (){


              var B_grade = [];
              var G_grade = [];


               $.each($("input[id^='student_grde_B']"), function(i, item) {

                 var grade_B =  $(item).val();

                 var stud_id_B = $(item).attr('rel');

                 B_grade.push({"studnt_B_id":stud_id_B,"studnt_grade_B":grade_B});

                     });

                  $.each($("input[id^='student_grde_G']"), function(i, item) {

                       var grade_G =  $(item).val();

                       var stud_id_G = $(item).attr('rel');

                         G_grade.push({"studnt_G_id":stud_id_G,"studnt_grade_G":grade_G});
                     });

                     subjct_id =  $('#subjects-list').val();
                      year_grade_level  = $('#year_grade_lvl').val();
                      sbjct_handler_id = $('#assign-handler-id').val();

                      $.ajax({

                          type:'POST',
                          url:'grades.php',
                          dataType:'json',
                          data:{'swtch_numbr':'1','subject_id':subjct_id,'year_level':year_grade_level,'subject_handler_id':sbjct_handler_id,'student_grades_boy':B_grade,'student_grades_girl':G_grade},
                          success:function (data){


                          }
                      });


                });

PHP:

<?php
include_once('DBconnect.php'); 



$switch_num = $_POST['swtch_numbr'];


switch ($switch_num) {
    case 1:         
        save_grades();
        break;


}
function save_grades(){
    session_start();

    $school_id = $_SESSION['school_id'];
    $faculty_id = $_SESSION['user_id_fac'];
    $subject_id = $_POST['subject_id'];
    $year_grade_level = $_POST['year_level'];
    $subject_handeler_id = $_POST['subject_handler_id'];
    $student_grades_boy = $_POST['student_grades_boy'];
    $student_grades_girl = $_POST['student_grades_girl'];


    $save_grades_boy = "INSERT INTO registrar_grade_archive 
                                    (registrar_archive_id,
                                    school_id,
                                     subject_id,
                                     grade,
                                     advisory_faculty_id,
                                     subject_handler_id,
                                     year_level,
                                     student_id) VALUES";

                    $values_boy = array();
                    $values_girl = array();

                    foreach ($student_grades_boy as $key=>$data) {
                                $student_id_B= $data['studnt_B_id'];
                                $grade_B = $data['studnt_grade_B'];

    $values_boy[$key] = '(\''.$school_id.'\', \''.$subject_id.'\',\''.$grade_B.'\',\''.$faculty_id.'\',\''.$subject_handeler_id.'\',\''.$year_grade_level.'\',\''.$student_id_B.'\')';
                            }

        $values_boy = implode(', ', $values_boy);

    $ready_save_grades_boy .= $values_boy;


                    if(@!mysql_query($ready_save_grades_boy)){
                        die('error insert'.mysql_error());

                        }

}

?>

But there’s an error when I checked on firebug says “You have an error in your SQL syntax;”

I can’t find what I’ve done wrong.. Please help, guys, because I’m just a newbie in Ajax and PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:03:17+00:00Added an answer on June 17, 2026 at 4:03 am

    It looks like you start storing the SQL in the variable $save_grades_boy and then try concatenating the values to $ready_save_grades_boy which doesn’t exist yet and therefore is treated as an empty string.

    Replace

    $ready_save_grades_boy .= $values_boy;
    

    With

    $save_grades_boy .= $values_boy;
    

    Or

    $ready_save_grades_boy = $save_grades_boy . $values_boy;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys (and gals) I'm having a problem using Assembly GetExportedTypes() in .NET 4.0.
Hey guys I'm having a big problem. I've been trying to set up my
Hey guys, I'm currently trying to implement a function using C that takes in
Hey guys, I'm having a bit of trouble with my ASP:RadioButtonList, searched Google and
Hey guys plz help I am trying to convert this html to jade using
Hey guys - I am having trouble setting up my Django urls file correctly
Hey guys I've been having some trouble skipping some unnecessary lines from the txt
hey guys having this really simple problem but cant seem to figure out have
Hey guys am having a bit of problems with my jQuery, I have all
Hey Guys i am currently trying to stopping one tableviewcell from being editable. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.