Jump to content

inserting data to data base


wassimjabar
 Share

Recommended Posts

 

hey basically my code is something like taxi meter but with time i have made functions that calculates money by minute whenever it reaches a minute the money will add by far i made a confirm button which when i click on it i want to send money and time values to data base how ever i had no errors in all my codes but still the values don't want to be sent to my db help me

<form id ="data" method ="post" >
    <h2 id ="done"></h2>

<div class="jumbotron jumbotron-single d-flex align-items-center" style="background-image: url(img/billard.jpg)">
    <div class="col-md-3 col-sm-10 text-center mt-2">
        <div class="shadow rounded feature-item align-items-center p-2 mb-2" data-aos="fade-up">
            <div class="my-4">
                <i class="lnr lnr-cog fs-40"></i>
            </div>
            <h4>Post 1 </h4>
                            <div id="timer">
                                <span id="hours">00:</span>
                                <span id="mins">00:</span>
                                <span id="seconds">00</span>
                                <br><span id="money">0TND</span>
                            </div>
                            <div id="controls">
                                <button id="start">Start</button>
                    <button id="stop">Stop</button>
                    <button id="reset">Reset</button>
                    <button id="confirm" >confirm</button><br>
                    <button id="tarifA">TarifA</button>
                <button id="tarifB">TarifB</button>
                <button id="tarifC">TarifC</button>
            </div>
            <p>Post de PS5</p>
        </div>
    </form>
  $('#confirm').click(function(e) {
        e.preventDefault();
        clearTimeout(timex);
         $.ajax({
         method: "post",
         url : "collect.php",
         data: $('#data').serialize(),
         datatype: "text",
         success : function (response){
             $('#done').html('done'),1000;}
         })});   
<?php


if (isset($_POST['money']))
{
   sleep(4);
   $servername='localhost';
   $username='root';
   $password='';
   $dbname = "khalil";
   $conn=mysqli_connect($servername,$username,$password,"$dbname");
   if($conn){print_r("connected ");}
   
     $money=$_POST['money'];
   

     
     $hours=$_POST['hours'];
     $mins=$_POST['mins'];
     $seconds=$_POST['seconds'];
    
     $sql = "INSERT INTO `history` (`prix`,`time1`,`date1`) VALUES (`$money`,`mins`,`wassim`)";
  
     // insert in database 
     $rs = mysqli_query($conn, $sql);
     
     if($rs)
     {
        
        $success= "done";
     }
     
       
} 

?>

 

Link to comment
Share on other sites

3 hours ago, benanamen said:

You should be using Prepared Statements. Never use variables in your query. Never trust user supplied data.

Nevertheless, does this look right to you?
 

VALUES (`$money`,`mins`,`wassim`)";

i fixed it but still can't insert em into database , the problem is these values are coming from js function  and i want to insert them in database i still didn't know what's exactly the problem

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.