skip to Main Content

Hi i want to change the last 4 digits of number with asterisk
For example: 123456789101

I want it to become 12345678**** in database (PHPMyAdmin)

This is my code

 if(isset($_POST['add'])){
        
    $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
        
    $voter = $_POST['voters_id']; (**I want the voters_id to be asterisk only last 4 digits**)
    }
        
    
 $sql = "INSERT INTO voters (voters_id, password) VALUES ('$voter', '$password')";
            
    if($conn->query($sql)){
                
    echo '<script language="javascript">';
                
    echo 'alert("Voters sucessfully insert")';
                
    echo '</script>';
                
    echo ("<script>location.href='index.php'</script>");
        
    }
        
    
            
    else{
               
     $_SESSION['error'] = $conn->error;
            
    }
        
    }

Is there any idea on how to solve this problem? Thank you in advance!

2

Answers


  1. Edited it to match what you want; here ya go:

        $id = "0123456789";
    
        $eid = function() use ($id){
            $half1 = substr($id, 0, strlen($id) -  4);
            return $half1."****";
        };
    

    Input:

    0123456789
    

    Output

    012345****
    

    Live Demo: http://sandbox.onlinephpfunctions.com/code/3ad1e3e028e696b1e8befe5e9a971ba468ba4d9e

    I just don’t understand how you’re going to get the original numbers back from the asterisks but to each is their own lol.

    Login or Signup to reply.
  2. Use this

    <?php echo substr($phone, 0, -4) . "****" ; ?>
    

    credits to https://beta.openai.com/playground

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search