wassimjabar Posted May 29, 2022 Share Posted May 29, 2022 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/314859-inserting-data-to-data-base/ Share on other sites More sharing options...
benanamen Posted May 30, 2022 Share Posted May 30, 2022 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`)"; Quote Link to comment https://forums.phpfreaks.com/topic/314859-inserting-data-to-data-base/#findComment-1596827 Share on other sites More sharing options...
wassimjabar Posted May 30, 2022 Author Share Posted May 30, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314859-inserting-data-to-data-base/#findComment-1596828 Share on other sites More sharing options...
Barand Posted May 30, 2022 Share Posted May 30, 2022 Have you checked what is being sent and received by your AJAX calls? (Browser/Developr tools/Network tab) Quote Link to comment https://forums.phpfreaks.com/topic/314859-inserting-data-to-data-base/#findComment-1596829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.