-1

When I insert data (date) in my table and click on the add button it changes it into 0000-00-00 instead of the entered date. Please tell me how to store the date into the javascript variable.

//php code
<?php
    $edate = mysqli_query($con, $_POST["edate"]);
    $query = "INSERT INTO expenses(edate, details, spent) VALUES('$edate', '$details','$spent')";
?>
<script>
    $(document).on('click', '#insert', function(){
    var edate = $('#data1').text(); 
</script>      
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
LeKenLu
  • 3
  • 1
  • Your PHP is completely wrong. See here for some good examples: https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement – Dharman Sep 27 '20 at 20:29

1 Answers1

0

First print your date in a hidden input field in your PHP file

<input type="hidden" class="myDate" value="$dateFromyourDatabase">

Then get it in your JS

var myDate = $(".myDate").val();

I have used html class attr, you can use whatevery seems easy to you

SOS9GS
  • 362
  • 1
  • 7
  • Thanks so much, I totally got your point. I was stuck with this for almost a week. Thanks ALOT! – LeKenLu Oct 01 '20 at 13:55