這是一個使用Jeditable的後端程式。
主要希望達成,當這個id所編輯的value中已存在這個value,就回傳重複,反之才上傳資料庫。
我的想法是:
程式如下,好像在while之後有些問題......請教一下大家,謝謝
<?php
$userAccount = $_COOKIE["account"];
$id = $_POST['id'];
$value = $_POST['value'];
list($field, $id) = explode('_', $id);
require_once("dbtools.php");
$link = create_connection();
$value = trim($value);
$sqlCheck = "SELECT `name` FROM table WHERE `id`='$userAccount'";
$database = "database";
mysqli_select_db($link, $database)
or die("開啟資料庫失敗: " . mysqli_error($link));
$resultCheck = mysqli_query($link,$sqlCheck);
while($fielddatas=mysqli_fetch_array($resultCheck))
{
$sqlCheck = "SELECT * FROM table WHERE `id`='$userAccount' AND `name`='$fielddatas[0]'";
$database = "database";
mysqli_select_db($link, $database)
or die("開啟資料庫失敗: " . mysqli_error($link));
$resultCheck = mysqli_query($link,$sqlCheck);
if($resultCheck)
{
echo "重複";
}
else
{
$sql = "UPDATE table SET `name` = '$value' WHERE num='$id'";
$database = "database";
mysqli_select_db($link, $database)
or die("開啟資料庫失敗: " . mysqli_error($link));
$result = mysqli_query($link,$sql);
echo $value;
}
}
?>
$sqlCheck = "SELECT name
FROM table WHERE id
='$userAccount' AND name
='$value'";
請問這邊是比對輸入的值跟相對應資料表欄位的值有沒有一樣嗎?
$database = "table";
mysqli_select_db($link, $database)
or die("開啟資料庫失敗: " . mysqli_error($link));
$resultCheck = mysqli_query($link,$sqlCheck);
$nums = mysqli_num_rows($resultCheck);
請問後面這串的意思是啥