"不正确"尝试通过表单更新时的数据库值

时间:2016-04-07 06:31:45

标签: php mysql database database-design database-connection

我的问题是当我填写表格中的" name"值,利用它,并将更新与该值相关的所有其他字段,我得到"数据库中没有提交名称的实例,"什么时候肯定有。我已经工作了好几个小时而且完全难过了。任何帮助将不胜感激!

Quick Notes:
$host="localhost"
$pw=password (My personal password)
$db="akimble" (Database name)
tables name="pctable" (Tables name)

phpMyAdmin Screenshot of Table Screenshot of Website Issue

<!DOCTYPE html>
<html>
    <head>
    <!-- Specifies Character Encoding Type (Unicode) -->
    <meta charset="UTF-8">

    <title>Database One's Edit Entry Table</title>

    <!-- Beginning of CSS -->
    <style type="text/css">
    body {
        margin-left: auto;
        margin-right: auto;
        width: 100%;
        max-width: 768px;
        text-align: center;
        width: 768px;
        font-family: "Times New Roman", Arial, Helvetica;
    }
    table {
        width: 768px;
        border: 2px;
        border-style: solid;
        border-color: black;
        text-align: center;
        color: black;
    }
    td {
        border: 2px solid;
    }
    </style>
    <!-- End of CSS -->

    <!-- Beginning of Body Section -->
    <body>
        <!-- Start of Menu -->
        <table class="pheader" width="768px" width="100%">
        <tr>
            <td>
                <h1>Database One's Files Source Code</h1>
            </td>
        </tr>
        </table>
        <table class="dbm"cellpadding="10" width="768px" width="100%">
            <tr>
                <td><a href="add_form.php">Add to Database</a></td>
                <td><a href="search_form.php">Search Database</a></td>
                <td><a href="edit_form.php">Edit Database Responce</a></td>
                <td><a href="view.php">View Database Entries</a></td>
                <td><a href="pages_sources.php">View Database's Page's     Sources</a></td>
            </tr>
        </table>
        <!-- End of Menu -->

        <!-- Start of Edit & Update Form -->
        <form action="edit_form.php" method="POST">
            <table cellpadding="10">
                <tr>
                    <td>
                    Please enter the name used on the entry you wish to update     and edit:
                    </td>
                    <td>
                    <input type="text" id="name" name="name">
                    </td>
                </tr>
                <tr>
                    <td>
                    Please enter your central processing unit (CPU) model(s):
                    </td>
                    <td>
                    <input type="text" id="cpu" name="cpu">
                    </td>
                </tr>
                <tr>
                    <td>
                    Please enter your motherboard model:
                    </td>
                    <td>
                    <input type="text" id="motherboard" name="motherboard">
                    </td>
                </tr>
                <tr>
                    <td>
                    Please enter your graphic processing unit (GPU) model(s):
                    </td>
                    <td>
                    <input type="text" id="gpu" name="gpu">
                    </td>
                </tr>
                <tr>
                    <td>
                    Please enter your random access memory (RAM) model(s):
                    </td>
                    <td>
                    <input type="text" id="ram" name="ram">
                    </td>
                </tr>
                <tr>
                    <td>
                    Please enter the storage device where your operating system (OS) is installed:
                    </td>
                    <td>
                    <input type="text" id="storage" name="storage">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                    <input type="submit" id="submit" name="submit" value="Update & Edit Entries">
                    </td>
                </tr>
            </table>
        </form> 
        <!-- End of Edit & Update Form -->

    <!--Beginning of PHP & MySQL Section -->
    <?php
    if (isset($_POST['submit'])){
        $name = $_POST['name'];
        $cpu = $_POST['cpu'];
        $motherboard = $_POST['motherboard'];
        $gpu = $_POST['gpu'];
        $ram = $_POST['ram'];
        $storage = $_POST['storage'];

        include ("connect.php");
//$host="localhost"
//$id="akimble"(My personal user account id)
//$pw=password (My personal password)
//$db="akimble" (Database name)
//table name="pctable" (Table's name)

        if ($name&&$cpu&&$motherboard&&$gpu&&$ram&&$storage){

        $conn = mysql_connect("localhost", $id, $pw); //Start of Establishing Connection
        if (!$conn) {
            die ("Error connecting: " . mysql_error());
        }

        $update = mysql_query ("SELECT * FROM pctable WHERE name= '$name'") or die ("There was an error with the query.");
        if (mysql_num_rows(!$update) != 0){
            mysql_query ("UPDATE pctable SET cpu='$cpu' WHERE name='$name'") or die ("There was an error updating.");
            mysql_query ("UPDATE pctable SET motherboard='$motherboard' WHERE name='$name'") or die ("There was an error updating.");
            mysql_query ("UPDATE pctable SET gpu='$gpu' WHERE name='$name'") or die ("There was an error updating.");
            mysql_query ("UPDATE pctable SET ram='$ram' WHERE name='$name'") or die ("There was an error updating.");
            mysql_query ("UPDATE pctable SET storage='$storage' WHERE name='$name'") or die ("There was an error updating.");
            echo "The update is complete";
        }
        else echo "There is no instance of the submitted name in the database";
        }
        else echo "Do not leave any fields empty";
    }
    ?>
    <!-- End of PHP & MySQL Section -->
    </body>
    <!-- End of Body Section -->

</html>

0 个答案:

没有答案