英文:
How can I insert a Data inputted in a textbox from an onclick Alert input event into DataBase
问题
UI
PHP提交脚本的代码
if (isset($_POST['rejectreason'])){
$Note = $_POST['rejection_reason'];
$whyreject = 'Rejection_Reason-' . $Note;
$sql = "UPDATE requestitem SET requestitem_UsefulNote='$whyreject'";
$query = $dbh->prepare($sql);
if ($query->execute()){
$success="拒绝成功,并发送原因。";
} else {
$error="抱歉,拒绝失败,请稍后重试。";
}
}
取消按钮的代码
<input type="hidden" id="rjctrsn-data" href="" name="rejection_reason">
<a type="submit" name="rejectreason" onclick="document.getElementById('rjctrsn-data').value = prompt('您确定要拒绝此项吗!:', '请说明拒绝的原因');"
value="" class="btn btn-xs delete-record" data-id="0">
<span style="font-size:25px" class="glyphicon glyphicon-remove text-danger" style="color:red"></span>
</a>
英文:
UI
code for the PHP Submit Script
if (isset($_POST['rejectreason'])){
$Note = $_POST['rejection_reason'];
$whyreject = 'Rejection_Reason-'.$Note;
$sql = "UPDATE requestitem SET requestitem_UsefulNote='$whyreject' ";
$query = $dbh->prepare($sql);
if ($query->execute()){
$success="Rejection Confirmed Successfully and Reason Sent.";
}else {
$error="Sorry, Rejection Failed, Try again Later.";
}
}
code for the cancel button
<input type="hidden" id="rjctrsn-data" href="" name="rejection_reason">
<a type="submit" name="rejectreason" onclick="document.getElementById('rjctrsn-data').value = prompt('Are you sure you want to Reject this Item ! :', 'Please State Reason for Rection');"
value="" class="btn btn-xs delete-record" data-id="0">
<span style="font-size:25px" class="glyphicon glyphicon-remove text-danger" style="color:red"></span>
</a>
答案1
得分: 1
触发点击警告输入事件并获取用户输入
<form action="submit_script.php" method="post">
<button type="button" onclick="showRejectionReasonAlert()">拒绝</button>
</form>
<script>
function showRejectionReasonAlert() {
var rejectionReason = prompt("请输入拒绝原因:");
if (rejectionReason != null) {
document.getElementById("rjctrsn-data").value = rejectionReason;
document.getElementById("yourFormId").submit();
}
}
</script>
在执行 SQL 之前,请确保正确设置数据库连接。
<?php
if (isset($_POST['rejection_reason']) && !empty($_POST['rejection_reason'])) {
$Note = $_POST['rejection_reason'];
$whyreject = 'Rejection_Reason-' . $Note;
$sql = "UPDATE requestitem SET requestitem_UsefulNote=:whyreject";
$query = $dbh->prepare($sql);
$query->bindParam(':whyreject', $whyreject);
if ($query->execute()) {
$success = "拒绝成功,原因已发送。";
} else {
$error = "抱歉,拒绝失败,请稍后重试。";
}
}
英文:
Trigger the onclick alert input event and get the user input
<form action="submit_script.php" method="post">
<button type="button" onclick="showRejectionReasonAlert()">Reject</button>
</form>
<script>
function showRejectionReasonAlert() {
var rejectionReason = prompt("Please enter the rejection reason:");
if (rejectionReason != null) {
document.getElementById("rjctrsn-data").value = rejectionReason;
document.getElementById("yourFormId").submit();
}
}
</script>
Ensure to properly set up your database connection before executing the SQL.
<?php
if (isset($_POST['rejection_reason']) && !empty($_POST['rejection_reason'])) {
$Note = $_POST['rejection_reason'];
$whyreject = 'Rejection_Reason-' . $Note;
$sql = "UPDATE requestitem SET requestitem_UsefulNote=:whyreject";
$query = $dbh->prepare($sql);
$query->bindParam(':whyreject', $whyreject);
if ($query->execute()) {
$success = "Rejection Confirmed Successfully and Reason Sent.";
} else {
$error = "Sorry, Rejection Failed, Try again Later.";
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论