Building a Online Lotto Web Application. Tutorial -1 : basic function of the lotto web application.(connecting mysql in website by function.php)

in #utopian-io3 years ago (edited)

PicsArt_10-10-09.37.32.png

Repository

https://github.com/kibriakk/lotto

You will learn From This tutorial.

  • How to make a online lottery managemment script & Site
  • Steem Payment Getway Setup
  • Auto Payment getway Building
  • User login,Registration System Building
  • Php to MySql Data input
  • MySql to Php data showing
  • Token Transaction System Building
  • Buy & Sell ticket System Build via Php and mysql
  • Text to QR code generator builder
  • Online live Chat plugin Builder
  • Admin mode build via php
  • Php from Builder.

Requirements

  • Php 5.1 or higher
  • My SQL 5.1 or higher
  • Hosting or Server
  • Basic knowledge on Php, My SQL, HTML,CSS

Difficulty

  • Intermediate

Description

I am kibria a web and blockchain Developer. It is my first contribution on utopian-io.

Today I will tech you How to build a lotto /lottery /gambling site using Php and MySQL without using any framework. To learn this you need only some basic knowledge about Php and MySQL.

The tutorial is so large. So I will post every tutorial part by part in my steemit blog.

So lets start-

Part-1: Connect php to MySQL database using function.php
  • Create MySQL database

  • Then create a file in your root folder and name it "function.php" or anyname.php

  • Edit the file using Notepad or other text editor.

    First write this code…

<?php
$baseurl = "https://domain.com";   //your base url
$sender = "[email protected]";    //your email address which will use for sending mail to user
    error_reporting(E_ALL);
    
$dbname = "lotto_lotto";    //database name
$dbhost = "localhost";       //database host name. Use localhost or 127.0.0.1 
$dbuser = "root";     //Write your database username into ""
$dbpass = "";     //Write your database password here into ""

Here <?php is used to start php code.

"$baseurl, $sender, $dbname, $dbhost, $dbuser, $dbpass"
is used as variable.

  • Change $baseurl value as your website url.
  • Change $sender value to your email.
  • Change the $dbname,$dbhost,$dbuser,$dbpass values to your database values.

Then write this code :

$basecurrency = "USD";

$basecurrency is define the Currency use in your website. You can change it to "STEEM" "SBD" "EURO" or etc.

Then write this code :

function connectdb()
{
    global $dbname, $dbuser, $dbhost, $dbpass;
    $conms = @mysql_connect($dbhost,$dbuser,$dbpass); //connect mysql
    if(!$conms) return false;
    $condb = @mysql_select_db($dbname);
    if(!$condb) return false;
    return true;
}

This code/function is used to connect the database with your website.

Then write the user system and active session function, username validator and password validator function,

function is_user()
{
    if (isset($_SESSION['username']))
        return true;
}
function redirect($url)
{echo "<meta http-equiv=\"refresh\" content=\"0; url=$url\" />";
    //header('Location: ' .$url);
    exit;
}
function valid_username($str){
    return preg_match('/^[a-z0-9_-]{3,16}$/', $str);
}
function valid_password($str){
    return preg_match('/^[a-z0-9_-]{6,18}$/', $str);
}

These is the main function to connect mysql in php website. But we need to build some other function for making lotto web application.

Here is some other function:
  1. Generating TRX id:

We should write the transaction id generating function which will help to generate TRX id.

//////////////////GENERATE TRX #
$trxd = date("ymd", time());
$trxr = rand(100,999);
$trxu = substr(uniqid(), 7);
$trxc1 = chr(rand(97,122));
$trxc2 = chr(rand(97,122));
$trxc3 = chr(rand(97,122));
$ok ="$trxc1$trxd$trxu$trxc3$trxr";
$txn_id = strtoupper($ok);
//////////////////GENERATE TRX #

here we use 8 variable to make a transaction ID. You can change it anything you want
First make some variable and add different type of value like date, random number, encrypted text etc.

Then make a variable named "$ok"
and add all the variable as its value.

Finnally use $txn_id variable and encrypted $ok variable.

2)USD to BTC converter:

function toBTC($usd){
$api = "https://blockchain.info/tobtc?currency=USD&value=$usd";         //blockchain api is here where $usd is the value in usd
$BTC = file_get_contents($api);
return $BTC; 
}   //this will show your value in BTC

$usd = value in usd
$BTC= value in btc

you can add any cryptocurrency converter function using API.

I will tech it letter.

  1. BTC payment address to QR code payment function:

This function will make a payment QR code which will be use for payment bitcoin.

function toScan($usd, $account){
$var = "bitcoin:$account?amount=$usd";
echo "<img src=\"https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=$var&choe=UTF-8\" title='' style='width:300px;' />";
}

Here
$account= btc address
$usd=value in usd.

Then we should end the php code by writing,

?>
The full code is simmilar like this,
<?php
$baseurl = "https://domain.com";      //input base url
$sender = "[email protected]";  //input sender email adress
    error_reporting(E_ALL);
    
$dbname = "lotto_lotto";   //input database name
$dbhost = "localhost";   //input database host
$dbuser = "root";   //input database username
$dbpass = "";   //input database password
$basecurrency = "USD";    //change USD to your base currency
function connectdb()
{
    global $dbname, $dbuser, $dbhost, $dbpass;
    $conms = @mysql_connect($dbhost,$dbuser,$dbpass); //connect mysql
    if(!$conms) return false;
    $condb = @mysql_select_db($dbname);
    if(!$condb) return false;
    return true;
}   //database connection function
function is_user()
{
    if (isset($_SESSION['username']))
        return true;
}   
function redirect($url)
{echo "<meta http-equiv=\"refresh\" content=\"0; url=$url\" />";
    //header('Location: ' .$url);
    exit;
}
function valid_username($str){
    return preg_match('/^[a-z0-9_-]{3,16}$/', $str);
}
function valid_password($str){
    return preg_match('/^[a-z0-9_-]{6,18}$/', $str);
}
//////////////////GENERATE TRX #
$trxd = date("ymd", time());
$trxr = rand(100,999);
$trxu = substr(uniqid(), 7);
$trxc1 = chr(rand(97,122));
$trxc2 = chr(rand(97,122));
$trxc3 = chr(rand(97,122));
$ok = "$trxc1$trxd$trxu$trxc3$trxr";
$txn_id = strtoupper($ok);
//////////////////GENERATE TRX #
function toBTC($usd){
$api = "https://blockchain.info/tobtc?currency=USD&value=$usd";
$BTC = file_get_contents($api);
return $BTC;
}  //usd to btc converter
function toScan($usd, $account){
$var = "bitcoin:$account?amount=$usd";
echo "<img src=\"https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=$var&choe=UTF-8\" title='' style='width:300px;' />";
}   //btc adress to QR code
?>

save the file as "function.php"

In the next tutorial tommorow we will learn about user registration, login, mysql database file building and admin system.

Next part list-
1)header building
2)registration system
3)contact us system
4)admin function
5)automatic payment system -
i) Paypal
ii) Perfect money
iii)skrill
iv)bitcoin
v)ETH
vi)LTC
vii)STEEM
vii)DOGE etc..
6)Withdraw System
7)Ticket Buy Sell System
8)Ticket / Balance Transfer System
9)ERC-20 Token Build
10)user profile, change password, and all other function.

Proof of Work Done

https://github.com/kibriakk/lotto

Sort:  
Loading...

I have started making a lotto website. I create the function.php.

thank you for the tutorial. Please post your next tutorial. I am waiting for that.

Thank you @kibria365,

I am very happy to see that some one sharing the tutorial of making lotto site. Please give us all the tutorials.

I am searching this kind of tutorial over the internet but I can not find it.

I hope Your tutorial can help me to build a lotto web app.

Dear @avantika
thank you. I will post my next tutorial part today.

Hi @kibria365!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @kibria365!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 1.34
TRX 0.12
JST 0.142
BTC 60204.96
ETH 2157.66
BNB 524.51
SBD 9.60