我的 PHP/SQL 脚本在我克隆的新表上不起作用,但在我复制新表的表上工作得很好:
SELECT * INTO slide FROM news
这是我的插入表格:
<div class="the-form" style="width:100%;">
<form class="userTrans" method="post">
<input type="hidden" name="act_userTrans" value="__insertNews_">
<p>
<label for="title">Title:</label>
<input type="text" name="title" id="title">
</p>
<p>
<label for="type">News Type:</label>
<input type="text" name="type" id="type">
</p>
<p>
<label for="autor">Author:</label>
<input type="text" name="autor" id="autor">
</p>
<input type="text" name="text2" id="text2">
<p class="form-footer">
<button class="button userTrans" style="background-color: #DB6D1D;">Publish News</button>
</p>
</form>
</div>
这是我的编辑表格:
<div class="the-form" style="width:100%;">
<form class="userTrans" method="post">
<input type="hidden" name="act_userTrans" value="__updateNews_">
<p>
<label for="title">Title:</label>
<input type="text" name="title" id="title" value="<?=$edit[title]?>"/>
</p>
<p>
<label for="type">News Type:</label>
<input type="text" name="type" id="type" value="<?=$edit[type]?>"/>
</p>
<p>
<label for="autor">Author:</label>
<input type="text" name="autor" id="autor" value="<?=$edit[autor]?>"/>
</p>
<input type="text" name="text2" id="text2" value="">
<input type="hidden" name="id" value="<?=$edit[id]?>">
<p class="form-footer">
<button class="button userTrans" style="background-color: #DB6D1D;">Publish News</button>
</p>
</form>
</div>
这是我更新和插入两种不同表格的过程:
if($activity == "__insertNews_")
{
$title = htmlspecialchars($_POST['title']);
$autor = htmlspecialchars($_POST['autor']);
$type = (int)$_POST['type'];
if(empty($_POST['type']) || empty($_POST['autor']) || empty($_POST['title']) || empty($_POST['text2']))
{
echo response(0,'Fill up all the forms.',0);
exit();
}
//echo $_POST[text2];
$news = mssql_query("INSERT INTO DB1.dbo.news (title,text,type,autor) VALUES ('$title','$_POST[text2]','$type','$autor') ");
echo response(1,'Publishing '.$title.' success!',0);
}
if($activity == "__updateNews_")
{
$title = htmlspecialchars($_POST['title']);
$autor = htmlspecialchars($_POST['autor']);
if(empty($_POST['autor']) || empty($_POST['title']))
{
echo response(0,'Fill up all the forms.',0);
exit();
}
$news = mssql_query("UPDATE DB1.dbo.news set title='$title',autor='$autor' WHERE id='$id' ");
echo response(1,'Editing '.$title.' success!',0);
}
因此,使用上面的那些脚本,我能够插入和更新dbo.news上的任何内容
但是,当我将DB1.dbo.news更改 为我创建的新表(DB1.dbo.slide)时,“INSERT”将不起作用。
我尝试使用相同的表单和处理脚本添加数据,“插入”在 dbo.slide 上不起作用,但是当我在 dbo.news 上测试它时,我可以插入数据。我还测试了 UPDATE,它适用于dbo.slide和 dbo.news。
现在我想知道,为什么 INSERT 的 SAME 脚本在其他表上工作,但在新表(dbo.slide)上不起作用。这确实令人困惑,因为我没有更改任何代码,我只是更改了要插入数据的表,并且 INSERT 函数停止工作。
调试此问题并找出导致此问题的原因的最佳方法是什么?