[英]Error with insert statement from PHP to MS Access
I've successfully login with a user account and now i will like to insert records.我已经使用用户帐户成功登录,现在我想插入记录。 As below is the code that has not been successful in inserting record.
如下是插入记录没有成功的代码。
<?php
session_start();
echo "Welcome: ". $_SESSION['role'];
?>
<?php
error_reporting(0);
if (!$_POST['submit'])
{
?
<html>
<body>
<br><br>
<fieldset >
Add a new user
<br>
<br>
<label for='username'>Username: </label>
<input type='text' name='username' id='username'/>
<label for='password'>Password: </label>
<input type='password' name='password' id='password' maxlength="50" />
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Role:
<br>
<select name="role">
<option value="" selected="selected"></option>
<option VALUE="Administrator"> Administrator</option>
<option VALUE="Secretary"> Secretary</option>
<option VALUE="Employee"> Employee</option>
</select>
<input type='submit' name='Submit' value='Submit' />
</form>
</fieldset>
<table width=100%>
</html>
</body>
<?php
}
else
{
$conn=odbc_connect("employee","","") or die (odbc_errormsg());
if (!$conn)
{
exit
("Connection Failed: " . $conn);
}
$query = "INSERT INTO empTable (empID, password, Role, Days left in MC, Days left in leave) VALUES" .
"('$_POST[username]', '$_POST[password]', '$_POST[role]', 14, 14)";
$result=odbc_exec($conn,$query) or die ("result error ".odbc_error().'-'.odbc_errormsg());
odbc_fetch_row($result);
odbc_close($conn);
}
After clicking the submit button and when i refresh my database, nothing comes out.单击提交按钮后,当我刷新数据库时,没有任何结果。 Why is that so?
为什么? Thanks alot
非常感谢
Access doesn't like column names with blanks. Access 不喜欢带有空格的列名。 You have to mask them with
[ ]
.你必须用
[ ]
掩盖它们。
Change your INSERT
query like this:像这样更改您的
INSERT
查询:
$query = "INSERT INTO empTable (empID, password, Role, [Days left in MC], [Days left in leave]) VALUES ..."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.