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
• 26,740 points
1,494 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,370 points

Related Questions In Blockchain

+1 vote
1 answer
0 votes
1 answer

PHP - Validate Multisig Bitcoin Wallet Address (with Leading 2 or 3)

 The answer to your question is given ...READ MORE

answered Apr 11, 2022 in Blockchain by Soham
• 9,710 points
1,967 views
+1 vote
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
• 26,740 points
839 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 aryya
• 7,460 points
740 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
• 26,740 points
45,219 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
1,923 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
886 views
0 votes
1 answer

Send Payment error in Blockchain API

The following code should help: $address = null; try ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
1,754 views
+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,370 points
6,505 views
0 votes
1 answer

Generating Bitcoin addresses from a xpubkey

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,370 points
1,482 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP