PHP Bitcoin validate from form

0 votes

I want to validate Bitcoin address from form. If someone enter invalid address it should echo "Please enter valid address". If address is valid, script should add this to database. I have this code. I only need validate function.

      <form method="post" action="index.php">
        <input type="text" name="address" placeholder="Address">
        <input type="checkbox" name="terms"> <label for="terms">I'm accepting the <a href="#terms">terms of use</a></label><br>
        <input type="submit" value="Submit">
      </form>
      <?php
        if(isset($_POST['address']) & isset($_POST['terms']))
        {
            include 'connect.php';
            $address=$_POST['address'];
            $date=date("Y-m-d");
            $request="INSERT INTO bitcoin (address, date) VALUES ('$address','$date')";
            mysqli_query($connect, $request) or die ("Error while writing to database! Try again...");
            mysqli_close($connect);
          }
       ?>
Sep 3, 2018 in Blockchain by digger
• 27,620 points
61 views

1 answer to this question.

0 votes

isValid($addr, $version)

$addr: A bitcoin address $version: The version to test against, defaults to MAINNET Returns a boolean indicating if the address is valid or not.

INSTALL

Download from GitHub or composer require linusu/bitcoin-address-validator

USE

use \LinusU\Bitcoin\AddressValidator;  

// This is a valid address and will thus return true.
AddressValidator::isValid('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i');

USING IT IN CODE

<?php 

    include 'connect.php';
    include 'LinusU\Bitcoin\AddressValidator.php';

    use \LinusU\Bitcoin\AddressValidator;  


    if(isset($_POST['address']) & isset($_POST['terms'])){
        $address=$_POST['address'];     
        if(AddressValidator::isValid($address)){
            // add
            $date=date("Y-m-d");
            $request="INSERT INTO bitcoin (address, date) VALUES ('$address','$date')";
            mysqli_query($connect, $request) or die ("Error while writing to database! Try again...");
            mysqli_close($connect);
        }else{
            // not valid
            throw new Exception('Invalid Bitcoin Address');
        }
    }

?>
answered Sep 3, 2018 by slayer
• 29,050 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

What is blockchain apart from bitcoin?

Blockchain is a decentralized database where the ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,620 points
12 views
0 votes
1 answer

Is it possible to claim Bitcoin Cash from an exchange that does not support it?

You can't claim BCH without knowing private ...READ MORE

answered Jul 17, 2018 in Blockchain by ariaholic
• 7,320 points
28 views
0 votes
1 answer

How to use bitcoin price as place holder in php?

You can do it by providing an ...READ MORE

answered Aug 21, 2018 in Blockchain by digger
• 27,620 points
32 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
2,126 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
105 views
0 votes
1 answer
+3 votes
3 answers

How to validate bitcoin address?

I found these 2 scripts online: Javascript: <html> <head> <script type="text/javascript" ...READ MORE

answered Aug 17, 2018 in Blockchain by slayer
• 29,050 points
675 views
0 votes
1 answer

Generating Bitcoin addresses from a xpubkey

Via https://bitcointalk.org/index.php?topic=1242247.0 var pubkey = ExtPubKey.Parse("xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz"); var newAddress = pubkey.Derive(0).Derive(0).PubKey.GetAddress(Network.Main); Console.WriteLine(newAddress); It ...READ MORE

answered Aug 21, 2018 in Blockchain by slayer
• 29,050 points
65 views