when user select hstes as counselling the code runs perfect but when they select josaa then code doesn't send any data to the database PHP PHP - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, April 30, 2023

when user select hstes as counselling the code runs perfect but when they select josaa then code doesn't send any data to the database PHP PHP

Basically I'm sending the data to predictor.php for payment using payumoney, now i've sent that and stored that into variables and again storing that into session variable so that i would be again be able to access at invoice.php after payment but for counselling value other than josaa, it works fine but for josaa it gives error as undefined index txnid and all.

predictor.php

if(isset($_POST['action']) && $_POST['action'] == 'payment_form_submit'){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $phone = $_POST['phone'];
    $gender = $_POST['gender'];
    $category = $_POST['category'];
    $counselling1 = $_POST['counselling'];
    $counselling = implode(",", $counselling1);
    $rank = $_POST['rank'];
    $state = $_POST['state'];
    $dd = $_POST['dd'];
    $mm = $_POST['mm'];
    $yy = $_POST['yy'];
    $code = $_POST['referral-code'];
    $dob = $dd.'-'.$mm.'-'.$yy;
    $amount = $_POST['amount'];
    $rand = rand();
    $txnid = 'txn'.$phone.$rand;
    $key = '$';
    $salt = '$';

    $hash = hash('sha512', $key . '|' . $txnid . '|' . $amount . '|' . $counselling. '|' . $name . '|' . $email. '|' . '|' . '|' .  '|' . '|' . '||||||' . $salt);
    session_start();
    $_SESSION['name'] = $name;
    $_SESSION['password'] = $password;
    $_SESSION['email'] = $email;
    $_SESSION['txnid'] = $txnid;
    $_SESSION['amount'] = $amount;
    $_SESSION['hash'] = $hash;
    $_SESSION['counselling'] = $counselling;
    $_SESSION['phone'] = $phone;
    $_SESSION['state'] = $state;
    $_SESSION['rank'] = $rank;
    $_SESSION['gender'] = $gender;
    $_SESSION['category'] = $category;
    $_SESSION['dob'] = $dob;
    $_SESSION['referral-code'] = $code;


   $response = '
        <input type="hidden" name="key" value="'.$key.'" style="font-size: 130%;" />
        <input type="hidden" name="txnid" value="'.$txnid.'" style="font-size: 130%;" />
        <input type="text" name="productinfo" value="'.$counselling.'" readonly style="font-size: 130%;" />
        <input type="text" name="amount" value="'.$amount.'" readonly style="font-size: 130%;" />
        <input type="text" name="email" value="'.$email.'" readonly style="font-size: 130%;" />
        <input type="text" name="firstname" value="'.$name.'" readonly style="font-size: 130%;" />
        <input type="hidden" name="surl" value="https://collegemitra.net.in/invoice.php" style="font-size: 130%;" />
        <input type="hidden" name="furl" value="https://collegemitra.net.in/payment.html" style="font-size: 130%;" />
        <input type="text" name="phone" value="'.$phone.'" readonly style="font-size: 130%;" />
        <input type="hidden" name="hash" value="'.$hash.'" style="font-size: 130%;" />
      ';
echo $response;

}



function user_exist($email){
    $conn = new PDO("mysql:host=localhost;dbname=db_collegemitra", "collegemitra", "Collegemitra@collegemitra");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql="SELECT * FROM users WHERE email=:email";
    $stmt= $conn->prepare($sql);
    $stmt->execute(['email'=>$email]);
    $result = $stmt->fetch(PDO::FETCH_ASSOC);

    return $result;
}

function register($name, $email, $password, $counselling, $state, $category, $txnid, $addedon, $gender, $rank, $dob, $phone, $premium, $random){
    $conn = new PDO("mysql:host=localhost;dbname=db_collegemitra", "collegemitra", "Collegemitra@collegemitra");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO users (name, email, password, premium, counselling, state, category, txnid, addedon, gender, jee_rank, dob, phone, unique_id) VALUES (:name, :email, :pass, :premium  , :counselling, :state, :category, :txnid, :addedon, :gender, :rank, :dob, :phone, :random)";
    $stmt = $conn->prepare($sql);
    $stmt->execute(['name'=>$name, 'email'=>$email, 'premium'=>$premium, 'pass'=>$password, 'counselling'=>$counselling, 'state'=>$state, 'category'=>$category, 'txnid'=>$txnid, 'addedon'=>$addedon, 'gender'=>$gender, 'rank'=>$rank, 'dob'=>$dob, 'phone'=>$phone, 'random'=>$random]);
return true;
}



//Increase no. of referrals
function referral_code_increase($code){
    $conn = new PDO("mysql:host=localhost;dbname=db_collegemitra", "collegemitra", "Collegemitra@collegemitra");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $query = "UPDATE users SET referrals = referrals+1 WHERE referral_code=:code";
    $stmt = $conn->prepare($query);
    $stmt->execute(['code'=>$code]);
    return true;
}




Invoice.php (After payment user gets redirected here)
<?php
namespace APITestCode;
session_start();
require_once './assets/php/predictor.php';
require_once('./collegemitra/assets/php/payment/PayU.php');
$payu_obj = new PayU();
$payu_obj->env_prod = 1;  //  1 for Live Environment/ 0 for SandBox Environment
$payu_obj->key = '%';
$payu_obj->salt = '%';

$txnid = $_SESSION['txnid'];
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$password = $_SESSION['password'];
$counselling = $_SESSION['counselling'];
$counselling_tables = explode(',', $counselling);
echo $counselling_tables;
echo $counselling;
$rank = $_SESSION['rank'];
$state = $_SESSION['state'];
$category = $_SESSION['category'];
$gender = $_SESSION['gender'];
$dob = $_SESSION['dob'];
$phone = $_SESSION['phone'];
$code = $_SESSION['referral-code'];
$hpass = password_hash($password, PASSWORD_DEFAULT);

$res = $payu_obj->getTransactionByTxnId($txnid);
$paid_on = $res['addedon'];
$random = rand();

if($res['status'] == 'success'){
  
    if(user_exist($email)){
        echo '<script type ="text/JavaScript">';  
        echo 'alert("User Already Exist!")';  
        echo '</script>';  
    }
    else{
        if(register($name,$email,$hpass,$counselling, $state, $category, $txnid, $paid_on, $gender, $rank, $dob, $phone, 1, $random)){
            $_SESSION['user'] = $email;
        }
        else{
            echo 'Something went wrong! try again later!';
        }
    }

    $users_data = user_exist($email);
    $uid = $users_data['id'];

    for($i =0; $i<count($counselling_tables);){
    
        $sql = "INSERT INTO $counselling_tables[$i](uid, name, rank, phone, category, email, state, counselling, gender) VALUES (:uid, :name, :rank, :phone, :category, :email, :state, :counselling, :gender)";
        $stmt = $conn->prepare($sql);
        $stmt->execute(['counselling'=>$counselling, 'uid'=>$uid, 'name'=>$name, 'rank'=>$rank, 'phone'=>$phone, 'category'=>$category, 'email'=>$email, 'state'=>$state, 'gender'=>$gender]);
        $i =$i+1;
}
    
}
referral_code_increase($code);
?>

Basically I'm sending the data to predictor.php for payment using payumoney, now i've sent that and stored that into variables and again storing that into session variable so that i would be again be able to access at invoice.php after payment but for counselling value other than josaa, it works fine but for josaa it gives error as undefined index txnid and all.



source https://stackoverflow.com/questions/76137946/when-user-select-hstes-as-counselling-the-code-runs-perfect-but-when-they-select

No comments:

Post a Comment