0
我已成功使用用户帐户登录,现在我想插入记录。以下是插入记录未成功的代码。从PHP插入语句到MS Access的错误
<?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);
}
点击提交按钮,当我刷新我的数据库时,什么都没有出来。为什么?非常感谢
嗨,施佩希特,谢谢。尽管添加了括号,insert语句仍然不起作用。 – Newbie 2012-04-11 05:14:12
@Newbie:尝试在构建INSERT语句后输出'$ query'变量的内容。这个陈述看起来有效吗?在Access中直接执行它(无PHP)时它是否工作?你能向我们展示完整的陈述吗?我想看看它。 – 2012-04-11 06:42:27
你将不得不使用括号密码 - “[密码]”,或者更好的是,不使用它,它是一个保留字http://support.microsoft.com/kb/248738。删除空格也好多了。 – Fionnuala 2012-04-11 07:46:33