<form action="delete.php" method="post" class="definewidth m20">
<table Id="agent" class="table table-bordered table-hover definewidth m10">
<tr>
<td class="tableleft">座機號碼</td>
<td><input type="text" id="phoneno" name="phoneno" value=""></td>
</tr>
<tr>
<td class="tableleft">客服群組</td>
<td><input type="text" id="group" name="group" value=""></td>
</tr>
<tr>
<td class="tableleft">工號</td>
<td><input type="text" id="id" name="id" value=""></td>
</tr>
<tr>
<td class="tableleft">姓名</td>
<td><input type="text" id="name" name="name" value=""></td>
</tr>
<tr>
<td class="tableleft">密碼</td>
<td><input type="text" id="password" name="password" value=""></td>
</tr>
<tr>
<td class="tableleft">電子信箱</td>
<td><input type="text" id="mail" name="mail" value=""></td>
</tr>
<td class="tableleft">狀態</td>
<td>
<input type="radio" id="status" name="status" value="1" selected=\"selected\"> 啟用
<input type="radio" id="status" name="status" value="0" selected=\"selected\"> 禁用
</td>
</tr>
<tr>
<td class="tableleft">角色</td>
<td>
<input type="radio" id="role" name="role" value="0" selected=\"selected\">一般客服
<input type="radio" id="role" name="role" value="1" selected=\"selected\">客服主管
</td>
<tr>
<td class="tableleft"></td>
<td>
<button type="submit" class="btn btn-primary" type="button">確定新增</button>
<button type="button" class="btn btn-success" name="backid" id="backid" onclick="location.href='person.php'">返回列表</button>
</td>
</tr>
</table>
</form>
以上是填寫資料的表單
按下保存後會跑以下程式碼 新增至資料庫
<?php
include('../info.php');
header("Content-Type:text/html;charset=utf-8");
$link = new PDO("sqlsrv:Server=$msdbhost,$msdbport;Database=$msdbname",$msdbuser,$msdbpass); //msSql
$link->exec("set names utf8");
if (!$link) {
echo "資料讀取錯誤";
exit;
}
$phoneno = $_POST['phoneno'];
$itri_group = $_POST['group'];
$id = $_POST['id'];
$name = $_POST['name'];
$password = $_POST['password'];
$mail = $_POST['mail'];
$status = $_POST['status'];
$role = $_POST['role'];
$sql="INSERT INTO person (phoneno, group, id, name, password, mail, status, role)
VALUES(?,?,?,?,?,?,?,?)";
$params = array($phoneno, $itri_group, $id, $name, $password, $mail, $status, $role);
$query = $link->prepare( $sql )
$query->execute($params);
header("Location:person.php");
?>
但是 不知道哪邊錯誤 資料都無法新增至資料庫
有確認是有連結到資料庫的
提供自己有在用的,
PHP5/PHP7都適用
<?php
$conn_array = array (
"UID" => "dbUser",
"PWD" => "dbPassword",
"Database" => "dnName",
"CharacterSet"=>"UTF-8",
"ReturnDatesAsStrings" => 1);
$conn = sqlsrv_connect('SQL001\SQLEXPRESS', $conn_array)or die ("連接SQL Server時發生錯誤");
?>
可參考:
https://oranwind.org/php-mssql-sqlsrv/
https://serverpilot.io/docs/how-to-install-the-php-sqlsrv-extension/
我在C#連MS-SQL參數是用 @phoneno,
然後定義@phoneno這個參數,
我沒有用PHP連過MS-SQL,
所以不確定語法怎麼寫.
除了檢查連結是否正常。也需要確定命令下達是否也正常。
我發現你沒對命令做判斷就轉頁了。
就算有跑錯誤也可能沒中斷轉頁跑掉了。
可以先試著寫判斷錯誤的程式。先不要放轉頁。