Can some one help me out

this is one of my php codes

<?php

require_once('connection.php');

function InsertRecord()
{
    global $con;
    $UserName = $_POST['UName'];
    $UserEmail = $_POST['UEmail'];
    //echo $UName, $Ufirstname;UserEmail
    $query = "insert into sample (Username,UserEmail) Values('$UserName','$UserEmail ')";

    $result = mysqli_query($con,$query); 

    if($result)
    {
        echo 'Your Record Has Been saved in the database';
    }
    else
    {
        echo 'please check your query ';
    }
}

//display data function *********************8

function display_record()
{
    global $con;
    $value = "";
    $value = '<table class = "table table-bordered">
<tr>
    <td> User ID </td>
    <td> User Name </td>
    <td> User Email </td>
    <td> Edit</td>
    <td> Delete  </td>

</tr>';

        $query = "select * from sample";
        $result = mysqli_query($con,$query);

        while($row = mysqli_fetch_assoc($result))
        {
            $value.= ' <tr>
                <td>'.$row['ID'].'</td>
                <td> '.$row['Username'].' </td>
                <td> '.$row['UserEmail'].' </td>
                <td><button class="btn btn-success" id="btn_edit" data-id='.$row['ID'].'><span class="fa fa-edit"></span>Edit</button></td>
                <td> Delete  </td>
            </tr>';
        }
        $value.='</table>';
        echo json_encode(['status'=>'success','html'=> $value]);
}

//get particular  record datail

function get_record()
{

    global $con;
    $ID = $_POST['UserID'];
    $query = " select * from sample  where ID='$ID' ";
    $result = mysqli_query($con,$query);

    while($row=mysqli_fetch_assoc($result))
    {
        $User_data = "";
        $User_data[ 0 ] = $row['ID'];
        $User_data[ 1 ] = $row['Username'];
        $User_data[ 2 ] = $row['UserEmail'];
    }
    echo json_encode($User_data); 
}

//update function

function update_value()
{
    global $con;
    $ID = $_POST['ID'];
    $update_familyname = $_POST['Username'];
    $update_firstname = $_POST['UserEmail'];


    $query =  $query = "update sample set Username='$update_familyname', UserEmail='$update_firstname' where ID ='$ID'";
    $result = mysqli_query($con,$query);
    if($result)
    {
        echo 'your record has been updated succerssfully';
    }else
    {
        echo 'please check your query';
    }

}


function delete_record()

{
   global $con;
    $Del_id = $_POST['ID'];
    $query = "delete from sample where ID = '$Del_id'";
    $result = mysqli_query($con,$query);
    if($result)
    {
        echo "your record has been deleted succesfully";
    } else
    {
         echo " can't be deleted, check query";
    }
}

?>

and the ajax code

$(document).ready(function()
{
  Insert_record();
  view_record();
  get_record();
  update_record();
  delete_record();
})


// insert record into the database

function Insert_record()

{
    $(document).on('click','#btn_register',function(){
        
    var User =$('#UserName').val();
    var Email = $('#UserEmail').val();

    if(User ==""  || Email=="")
    {
        $('#message' ).html('Please Fill in the Blanks');
    }
    else
    {
        $.ajax({
            url : 'insert.php',
            method: 'post',
            data :{UName:User,UEmail:Email},
            success: function(data)
            {
                $('#message' ).html(data);
                $('#Registeration').modal('show');
                $('form').trigger('reset');
                view_record();
            }
        })
    }
     
    })

    $(document).on('click','#btn_close',function()
    {
      $('form').trigger('reset');
      $('#message' ).html('');

    })
}


//displaying records javascript ************ kim xtion

function view_record()
{
    $.ajax(
        {
        url : 'view.php',
        method: 'post',
        success: function(data)
        {
            data = $.parseJSON(data);

            if(data.status=='success')
            {
               $('#table').html(data.html)
            }
        }
    })
}

//get particular record*********************

function get_record()
{
    $(document).on('click','#btn_edit',function()
    {
var ID = $(this).attr('data-id');
 
$.ajax(
    {
        url: 'get_data.php',
        method: 'post',
        data:{UserID:ID},
        dataType:'JSON',
        success: function(data)
        {
           console.log(data[10]);
        }


    })

    
  

    })
}


//update record

function update_record()
{

    

    $(document).on('click','#btn_update',function()
    {


        var UpdateID =$('#ID').val();
        var UpdateUser = $('#UP_familyname').val();
        var UpdateEmail =$('#UP_firstname').val();


        if(UpdateUser=="" || UpdateEmail=="" )
        {
            $('#up-message').html('please fill in the blanks');
            $('#update').modal('show');
        }
        else
        {
            $.ajax(
            {
             url: 'update.php',
             method: 'post',
             // U_id is my personal varriable its no where i just created it
             // U_id is my personal varriable its no where i just created it

             data:{ID:UpdateID,Username:UpdateUser,UserEmail:UpdateEmail},
             success: function(data)
             {
                $('#up-message').html(data);
                $('#update').modal('show');
                
             }

            })
        }
    })
}



// //delete function ************be careful the trick is here

function delete_record()
{
    $(document).on('click','#btn_delete',function()
    {
     var Delete_id = $(this).attr('data-id1');
     $('#delete').modal('show');
     $(document).on('click','#btn_delete_record',function()
     {
        $.ajax(
            {
              url:'delete.php',
              method: 'post',
              data:{ID:Delete_id},
              success: function(data)
              {
                 $('#delete-message').html(data);
                 view_record();
              }
     
            }
        )
     })

    // console.log(Delete_id);

  

    })
}

when I execute this code in my update modal, the code only returns the first character o of the UserEmail and the first character of the UserName.

can anyone help me

can you place your code between code tags please

None of that php code would get called as it is.

How is that returning ANYTHING?

As @astonecipher says… the external PHP script that your AJAX routing is calling would never do anything.

Its just a bunch of functions.

When/how does your fist function *(function InsertRecord()) get executed?

Sponsor our Newsletter | Privacy Policy | Terms of Service