gpt4 book ai didi

javascript - 从文本字段中抓取文本并用它更新数据库

转载 作者:行者123 更新时间:2023-11-29 12:52:40 25 4
gpt4 key购买 nike

我试图从文本字段中获取文本,然后用它来更新我的数据库。我尝试过使用 session、get、post 和 cookie 来使用 php 获取值,但这不起作用。我是 php 新手,所以我认为这是空白的,因为它是服务器端的。我用 javascript 做到了这一点,它获取了值,但我不知道如何将它与 php 一起使用或更新 mysql。任何帮助表示赞赏。这是我的一些示例代码:我在单独的 php 页面上进行了更新,但我的文本区域的输入甚至没有被抓取

<?php

function update_db(){
// echo $_POST["comment"];
$nenabled = $_GET['enabled'];
$comments_new = htmlspecialchars($_GET['comment']);
$nemail = $_GET['email'];

echo ("<script>console.log('$comments_new')</script>");
?>

<form method ="get" action ="update_user.php">
<input type="hidden" name = "enabled" value = "nenabled">
<input type="hidden" name = "comments" value = "comments_new">
<input type="hidden" name = "email" value = "nemail">

<input type="submit" >

<script>

function doFunction() {

var com = document.getElementById("comment");
alert(com.value);
// var comment = '<?php update_db(); ?>';
}

</script>

最佳答案

你有这样的东西:-

<input type="hidden" name = "comments" value = "comments_new">

那你怎么能期待

 document.getElementById("comment");

会起作用吗?您应该在 html 中添加 id,例如:-

 <input type="hidden" id="comment" name = "comments" value = "comments_new">

关于javascript - 从文本字段中抓取文本并用它更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24498012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com