0

我正在尝试在文本框中输入一个值并让它触发数据库的更新语句,但帖子.val()返回一个空白值。

这是功能:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
     function save_a9(id) {
        $.post('response6.php', {starID:id, starURL: $('#starurl').val()}, 
            function(result) { 
                alert(result); 
                window.location.reload();
        });
    }
</script>

这是按钮和文本框:

    echo "<br><b>request to join site: {$row9['count']}</b><br>";
while ($row99 = $prep99->fetch(PDO::FETCH_ASSOC)) {
    echo "{$row99['starID']} , {$row99['starName']} = {$row99['twitter']}";
    if ($row99['guest'] == 0) {
        $guest = 'ongoing';
    };
    if ($row99['guest'] == 1) {
        $guest = 'guest';
    };
    if ($row99['guest'] == 2) {
        $guest = 'PLEASE SELECT ONE';
    };
    echo " ~ $guest ~ <br>";
    echo "<input type='text' name='starurl' value='{$row99['starURL']}' id='starurl' style='width:100px; height:30px;'/>";
    echo "<br><button onclick='save_a9({$row99['starID']})'>Approve</button><button onclick='save_d9({$row99['starID']})'>Disapprove</button><br>";
}

这里是 response6.php:

<?php
include("db_conn.php");
$sql = "update stars set approved = 1, starURL = ? where starID = ?";
$qc = $pdo_conn->prepare($sql);
$qc->execute(array($_POST['starURL'], $_POST['starID']));
echo 'saved';
?>
4

1 回答 1

1

我会改用属性 id 。例如

<button id="button-id">Click me</button>

并在 jQuery 中使用它。Javascript 示例

于 2013-09-10T03:19:07.827 回答