简体   繁体   中英

how to store id=“getdobtval” into database?

Hi i want insert javascript based genarated value into "input value attribute",

my code below like this when i scroll range slider its showing price in id="getdobtval" but when am going buynow its not inserting into database

<form action="" method="post">                                              
    <input id="slider-bottom" type="text" name="hrate" data-slider-min="600" data-slider-max="100000" data-slider-step="1" data-slider-value="600" data-slider-tooltip="show"/>
    <output id="getdobtcval" name="getdobtval"></output>
    <input type="hidden" name="<?php $_SESSION['sess_user']; ?>">
    <input type="submit" name="buynow" >
</form>

i changed value into input text now id="getdobtval" not showing generated value in form

<form action="" method="post">                                              
    <input id="slider-bottom" type="text" name="hrate" data-slider-min="600" data-slider-max="100000" data-slider-step="1" data-slider-value="600" data-slider-tooltip="show"/>
    <input type="text" id="getdobtcval" name="getdobtval">
    <input type="hidden" name="<?php $_SESSION['sess_user']; ?>">
    <input type="submit" name="buynow" >
</form>

my php form like this

<?php
    if(isset($_POST['buynow'])){                                                    
        $h_rate = $_POST['hrate'];
        $hrate_price = $_POST['getdobtval'];
        $in_username = $_SESSION['sess_user'];      
        $conn = mysqli_connect("localhost", "root", "", "buyrate");                                                     
        $sql = "INSERT INTO buy_rate(hrate,hrate_price,in_username) VALUES('$h_rate','$hrate_price','$in_username')";       
        if (mysqli_query($conn, $sql)){
            echo "Sucessfully Added";
        }else{
            echo "error";
        }       
            mysqli_close($conn);
    }                                       
?>

my javascript like this

<script type="text/javascript">
    jQuery(document).ready(function() { 
    $('#slider-bottom').slider().on('slide', function(ev){
    var finalvalue='';
    var finalbtvalue='';
    var finalbtprice='';
    var finalbitvalue='';
    finalbtprice= 250;
    var newVal = $('#slider-bottom').data('slider').getValue();
    var textval = parseInt(newVal);

    if( textval >= 600 && textval < 6000){
        finalvalue=  0.075; 
        finalbitvalue = textval * finalvalue;
        }else if(textval >=6000 && textval < 30000 ){
            finalvalue= 0.070;
            finalbitvalue = textval * finalvalue;
        }else if(textval >= 30000 ){
            finalvalue= 0.065; 
            finalbitvalue = textval * finalvalue;
        }
        finalbtvalue = finalbitvalue/finalbtprice;
            if(finalbtvalue){
                $("#getdobtcval").html("<strong>"+finalbtvalue.toFixed(8)+"</strong>");
            }
    });

        $('#slider-bottom').sliderTextInput();
    });     
</script>

how to insert javascript based genarated value into "input value attribute", help me

i have update my answer

first you check that when you check amount then this field is empty or not <input type="hidden" id="getdobtval" name="getdobtval"> . type="hidden" change to type="text"

second change insert query

$sql = "INSERT INTO buy_rate(hrate,hrate_price,in_username) 
            VALUES('".$h_rate."','".$hrate_price."','".$in_username."')";

use concatenation in variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM