简体   繁体   中英

SQL statements via php in javascript

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?

由于PHP是一种服务器端语言,并且您将计算绑定到JS回调,因此无法正常工作,请检查答案,这是一个非常相似的问题。

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"');   
?>

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