Saturday, 17 June 2017

php - how to save data dynamically to database

JQUERY CODE




 $(document).ready(function () {
$("#add").click(function () {
$(".left .inputs").append("
  • ");
    $(".right .inputs").append("
  • ");
    });
    });


    MY PHP CODE




        $con = mysql_connect ("localhost","root","") or die('cannot connect to database error: '.mysql_error());
    if (isset($_POST['name']) && isset($_POST['grade']))
    {

    $desk_report = $_POST['name'];//contains array value
    $desk_action = $_POST['grade'];//contains array value
    foreach($desk_report as $key=>$user) { //Loop through arrays
    if (!empty($desk_report[$key]) && !empty($desk_action[$key])) {

    mysql_select_db("quickbook", $con);
    $sql = "INSERT INTO student_reg(relative_name,relative_grade) VALUES ('$desk_report[$key]','$desk_action[$key]')";
    if ($sql_run = mysql_query($sql)) {
    echo 'ok.';
    } else {
    echo '*Sorry, we couldn\'t register you at this time. Try again later.';
    }
    }
    }
    }

    ?>


    I want to add inputs data to database.i created a code.but this is not working .can you help me?

    No comments:

    Post a Comment

    c++ - Does curly brackets matter for empty constructor?

    Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...