简体   繁体   English

PHP 代码中的 SQL 查询没有将正确的信息写入数据库

[英]SQL Query within PHP code does not write the correct information to database

I have two query's one that is supposed to update existing data, and one that is supposed to insert new data.我有两个查询,一个应该更新现有数据,一个应该插入新数据。 The insert query is inserting the wrong data though.尽管插入查询插入了错误的数据。 It is inserting the data that is being sent to the update query.它正在插入发送到更新查询的数据。

I have tried moving the function that has the insert query to different files.我尝试将具有插入查询的函数移动到不同的文件。 The same problem still exists.同样的问题仍然存在。 Interestingly enough, if I comment out the update query, the insert query will work perfect.有趣的是,如果我注释掉更新查询,插入查询将完美运行。 As of now, the update query works fine.截至目前,更新查询工作正常。 Another interesting issue is the alert right below the insert query does not work.另一个有趣的问题是插入查询正下方的警报不起作用。 I have not been able to get it to show up at all.我根本无法让它显示出来。 Any help would be greatly appreciated!任何帮助将不胜感激!

// update query
mssql_query("UPDATE ERP_VIEW.dbo.NCRfaults SET faultID = $riptionold[$f]', 
rcID = '$firstchar', qty = '$faultqtyold[$f]'
WHERE ncrID = '$ncr_id'");

// insert query
<?php
    $q2 = "INSERT INTO ERP_VIEW.dbo.NCRfaults (ncrID, faultID, rcID, qty)
    VALUES ('$ncr_id','$fdescription[$f]', '$firstchar2', '$faultqty[$f]')";
?>
<script type="text/javascript">
    alert("<?php echo $q2; ?>")
</script>

<?php

 mssql_query($q2);

Well everyone, I figured it out.好吧,大家,我想通了。 I am very sorry to have wasted anyones time.我很抱歉浪费了任何人的时间。 I really appreciate all of the reply's.我真的很感激所有的回复。 I called the insert, and then the update.我调用了插入,然后调用了更新。 So I was updating right over the fresh insert.所以我正在更新新的插入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM