gpt4 book ai didi

php - 检查值是否已存在不起作用

转载 作者:行者123 更新时间:2023-11-30 01:37:05 26 4
gpt4 key购买 nike

我有一个函数,如果您在下拉菜单中选择一个值,我的代码将使用所选值更新数据库。现在我尝试添加一个检查来检查该值是否已存在于数据库中。但这不起作用。我做错了什么?

测试.php

<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<link href="style.css" rel="stylesheet" type="text/css">
<script>
function updateDb() {
$.post("buh.php", $("#form").serialize());
}
</script>
</head>
<body>
<form id="form">
<?php
include 'Includes/database_connection.php';
$sql = "select * FROM sims ORDER BY phonenr asc" ;
$result = mysql_query($sql,$con);
$id1 = $_GET["id1"];
echo "<input type='hidden' id='hidden' name='hidden' value='$id1'>";
echo "<select id='select' name='select' onChange='updateDb()'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['phonenr'] . "'>" . $row['phonenr'] . "</option>";
}
echo "</select>";
?>
</form>
<?php
echo '<a href="javascript:window.close()">Sluit venster</a>';
?>
<body>

Buh.php

<?php
include 'Includes/database_connection.php';
$sql = "select * FROM sims WHERE phonenr='".mysql_real_escape_string($_POST["select"])."'" ;
$result = mysql_query($sql,$con);
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$id1 = mysql_real_escape_string($_POST["hidden"]);
$checkID = mysql_query("SELECT sim_id from pairings WHERE sim_id = '$id'");
if (mysql_num_rows($checkID) > 0) {
if(confirm("Simkaart is al gekoppeld weet u zeker dat u deze wilt vervangen?")){
mysql_query("UPDATE pairings SET sim_id='$id' WHERE unit_id='$id1'")
or die(mysql_error());
}
}
else {
mysql_query("UPDATE pairings SET sim_id='$id' WHERE unit_id='$id1'")
or die(mysql_error());
}
}

最佳答案

通过更改修复它

 if(confirm("Simkaart is al gekoppeld weet u zeker dat u deze wilt vervangen?")){

到 JavaScript 函数

谢谢!

关于php - 检查值是否已存在不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16734889/

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