首页 > 解决方案 > 如何根据输入值使用javascript在mysql中插入数据

问题描述

function message() {
    $connection=mysqli_connect("localhost","root","","halcondentalclinic");
    var s = document.getElementById('edit_otherValue');
    if (s=="Crown") {
    <?php  
      $try18s=="Crown";
      $db="INSERT INTO tooth1(treatment)VALUES('$try18s')";
      $db_run=mysqli_query($connection,$db);
    ?>
  }
 }
<input type=text name=edit_otherValue id=edit_otherValue value="" />
<button onclick="message()" type="submit" name="treatmenthistoryupdatebtn" class="btn btn-primary">Save</button>

如何根据输入值使用 javascript 在 MySQL 中插入数据 我只是 javascript 的初学者。

标签: javascripthtmlmysql

解决方案


就像评论中说的那样,你不能用“简单的”javascript来做。

您链接的函数“消息”是用 PHP 编写的,要使用您的 JS 代码调用它,您需要执行 ajax 调用。

网上有很多资源:


推荐阅读