0

i'd like to know if it's allowed, i mean it worked for me, but is it a good practice? if not, what issues i will be dealing with ahead... i'm a php/script virgin btw.

// button
<button type="button" class="btn btn-primary" id="Submit-button" >Save changes</button>

<script>
$("#Submit-button").click(function() {
<?php 
$db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$result = $db_connection->query('update reservation set gm_submit="Y"');    
?>
});
</script> 

-------UPDATE---------------

k.. here's what i did... and it worked fine...

$("#SaveButton").click(function() {
    $.ajax({
      url: 'db.php',
      type: 'POST',
      data: {}
    });

});

i'm fine by this?

2
  • 1
    use ajax instead of js Commented Dec 2, 2013 at 9:31
  • No you should not use this. Instead you should make an ajax call to the php script that will do the same task for you...adding server side language to the client site language is a bad practice i think Commented Dec 2, 2013 at 9:32

2 Answers 2

0

Use ajax post and process the db updation.

$.ajax({
url: 'db.php',
type: 'POST',
data: {}
});

DB.php

<?php 
$db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$result = $db_connection->query('update reservation set gm_submit="Y"');   
?>
0

This cannot work since PHP is a server side language and your binding your computation to a JS callback, check this answer, it's a very similar problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.