插入到不工作的一个表中,但可以在其他表上工作&更新也可以吗?

g0czyy6m  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(323)

我的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”将不起作用。
我尝试使用相同的表单和处理脚本添加数据,“insert”在dbo.slide上不起作用,但是当我在dbo.news上测试它时,我能够插入数据。我还测试了这个更新,它在dbo.slide和dbo.news上都工作。
现在我想知道,为什么insert的相同脚本在另一个表上工作,但在新表(dbo.slide)上不工作。这确实令人困惑,因为我没有更改任何代码,我只是更改了正在插入数据的表,插入函数停止工作。
调试此问题并找出导致此问题的原因的最佳方法是什么?

c9x0cxw0

c9x0cxw01#

mssql_查询函数在较新的php版本中不再存在。我建议您使用pdo,因为它的一个优点是减少了常用的插入和更新操作,并且通过sql注入可以安全地抵御恶意攻击
但是现在,没有你我帮不了你 DB1.dbo.slide 列和 DB1.dbo.slide 列和您的 DB1.dbo.slide 插入查询。
因此,要获得主要帮助,请查看 DB1.dbo.slide 列并将其与 DB1.dbo.news . 然后根据 DB1.dbo.slide 柱。
如果您的插入查询适用于 DB1.dbo.news ,请确保插入对的查询 DB1.dbo.slide 这是不对的

相关问题