0

我已经使用用户帐户成功登录,现在我想插入记录。如下是插入记录没有成功的代码。

<?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: &nbsp;</label>  
<input type='text' name='username' id='username'/>  
<label for='password'>Password:&nbsp;</label>  
<input type='password' name='password' id='password' maxlength="50" />  
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Role: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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);
}

单击提交按钮后,当我刷新我的数据库时,什么也没有出现。为什么呢?非常感谢

4

1 回答 1

0

Access 不喜欢带有空格的列名。你必须用[ ].

像这样更改您的INSERT查询:

$query = "INSERT INTO empTable (empID, password, Role, [Days left in MC], [Days left in   leave]) VALUES ..."
于 2012-04-11T05:04:17.333 回答