PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-如何在重复的列值上更新mySQL键大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在编写将发布到@L_197_0@数据库PHP应用程序.我的那部分工作正常,但是我有一个名为repID的列,其中将包含客户端修复ID.

内容添加数据库的方式是通过我网站上的管理员进行的.我想这样做,以便如果技术人员输入现有的repID,它将只为此更新密钥.而不是复制具有不同修复状态的副本

PHP

$repID = @L_197_0@_real_escape_String($_POST['repID']);
$clientName = @L_197_0@_real_escape_String($_POST['clientName']);
$devModel = @L_197_0@_real_escape_String($_POST['devModel']);
$repStatus = @L_197_0@_real_escape_String($_POST['repStatus']);
$tracking = @L_197_0@_real_escape_String($_POST['tracking']);
$sql = @L_197_0@_query("INSERT INTO status (`repID`, `clientName`, `devModel`, `repStatus`,     `tracking`) VALUES ('$repID','$clientName','$devModel','$repStatus', '$tracking');");

输入页面

<?PHP
include_once('../resources/init.PHP');
$query = "SELECT * FROM status WHERE repStatus != 'Finished';";
$result = @L_197_0@_query($query);
$num = @L_197_0@_numrows($result);
@L_197_0@_close();
$random = rand(1000000000, 9999999999);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
    <head>
        <title>Add A Repair</title>
    </head>
    <body>
        <div id="wrapper">
            <div id="application">
                <div id="randomNum">
                    <?PHP echo $random; ?>
                </div>
                <form method="post" action="insert.PHP">
                    <div id="repID">
                        <label for="repID">Repair ID</label>
                        <input type="text" name="repID" />
                    </div>
                    <div id="clientName">
                        <label for="clientName">Client Name</label>
                        <input type="text" name="clientName" />
                    </div>
                    <div id="devModel">
                        <label for="devModel">Device Model</label>
                        <input type="text" name="devModel" />
                    </div>
                    <div id="repStatus">
                        <label for="repStatus">Repair Status</label>
                        <SELEct name="repStatus">
                            <option value="Diagnosis Stage">Diagnosis Stage</option>
                            <option value="Problem Found">Problem Found</option>
                            <option value="Possible Solution">Possible Solution</option>
                            <option value="Parts ordered">Parts ordered</option>
                            <option value="Parts Recieved">Parts Recieved</option>
                            <option value="Parts/Software Installation Stage">Parts/Software       m  Installation Stage</option>
                            <option value="TesTing Stage">TesTing Stage</option>
                            <option value="Finished">Finished</option>
                        </SELEct>
                    </div>
                    <div id="tracking">
                        <label for="tracking">Tracking number</label>
                        <input type="text" name="tracking" />
                    </div>
                    <div id="submit">
                        <input type="submit" value="Submit" />    
                    </div>
                </form>
                <div id="currentClients">
                    Current Clients
                    <br /><br />
                    <table border="0" cellspacing="2" celLPADding="2">
                        <tr>    
                            <th>Repair ID</th>
                            <th>Client Name</th>
                            <th>Device Model</th>
                            <th>Repair Status</th>
                            <th>Tracking</th>
                        </tr>
                        <?PHP
                        $i = 0;
                        while ($i < $num) {
                            $v1 = @L_197_0@_result($result, $i, "repID");
                            $v2 = @L_197_0@_result($result, $i, "clientName");
                            $v3 = @L_197_0@_result($result, $i, "devModel");
                            $v4 = @L_197_0@_result($result, $i, "repStatus");
                            $v5 = @L_197_0@_result($result, $i, "tracking");
                            ?>
                            <tr>
                                <td><?PHP echo $v1; ?></td>
                                <td><?PHP echo $v2; ?></td>
                                <td><?PHP echo $v3; ?></td>
                                <td><?PHP echo $v4; ?></td>
                                <td><?PHP echo $v5; ?></td>
                            </tr>
                            <?PHP
                            $i++;
                        }
                        ?>
                    </table>
                </div>
            </div>
        </div>
    </body>
</html>

解决方法:

使用@L_197_0@的INSERT … ON DUPLICATE KEY UPDATE.当然,请确保repID是主键或唯一键.

大佬总结

以上是大佬教程为你收集整理的php-如何在重复的列值上更新mySQL键全部内容,希望文章能够帮你解决php-如何在重复的列值上更新mySQL键所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: