php - Update database phone number

241

Currently my running program, when I click the submit new phone number button, my ajax shows a response pop up that is empty.

I don't have any running errors so I don't see the issue.

main index.php file:

case 'updatephone' :
    include('assets/header.php'); // create top box
    include('assets/sidemenu.php'); // create side menu
    // use a template to display result
    include('views/displayUpdatePhoneForm.php');
    include('assets/footer.php'); // create footer
    break;

case 'changephone' :
    $sql = 'update members set mobilePhone=:mobilePhone where indID=:indID';
    $phone = $_POST['mobilePhone'];
    $values = array(':indID'=>$_POST['indID'], ':mobilePhone'=>$phone);
    $stm = $db->prepare($sql);
    $result = $stm->execute($values);
    echo $result;
    break;

displayUpdatePhoneForm.php

<h4>Changing Mobile Phone</h4>
<p>Enter new number: <input type='tel' id='newPhone' />
<button type='button' class='btn btn-primary' id='updatephone' >Change  Phone</button>
</p>

script.js

$(document).ready(function(){
    url = '/cs382/cookead06/final/final_app';

    if ($('#uid').val() != '-1'){
        $('#sign-in' ).hide();
        $('#sign-out').show();
    }

    $('#p2').on('change', function(){
        $('#form2').submit();
    });
    $('#p3').on('change', function(){
        $('#form3').submit();
    });
    $('#p4').on('change', function(){
        $('#form4').submit();
    });


    // validate user

    $('#updatephone').on('click', function(){
        var f_id = $('#uid').val();
        var phone = $('#newPhone').val();
        $.ajax({
              type : 'post',
              url : url + '/index.php?action=changephone',
              data : 'indID=' + f_id + '&mobilePhone='+ phone,
              success : function(response){
                    alert(response);
               }
          });
     });



    $('#signInBtn').on('click', function(){
        var username = $('#username').val();
        var password = $('#passwd').val();
        var data_items = 'username='+username + '&passwd=' + password;
        $.ajax({
            type : 'post',  // type: get or post
            url : url + '/index.php?action=checklogin',  // define server-side script
            data : data_items,  // define data to be sent
            success : function(response){
               if (response != -1){
                  // hide login information
                  $('#username, #passwd').val('');
                  $('#login-content, #sign-in').hide();
                  $('#sign-out').show();
                  // update the value of 'uid'
                  $('#uid').val(1);
                  // display user's name
                  $('#user-info').text(response);
                  $('#update-link').removeClass('hidelink').addClass('displaylink');
                } else
                  alert("Invalid user");
              }
         });
     });
});

enter image description here

744

Answer

Solution:

Sorry, read wrongly..

I re-read it and I can see that you are printing $result that is = to $stm->execute($values); that is a sql query, if the query executes successfully, it won't show any message, only if you implemented an echo on the function execute..

425

Answer

Solution:

Surprisingly, the issue was at line:

$sql = 'update members set mobilePhone=:mobilePhone where indID=:indID';

where members was suppose to cs_members(name of table)

People are also looking for solutions to the problem: Opening a Text File using PHP - Fixing the Format

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.