2

所以我和我的朋友得出一个结论,就是 $_email 变量搞砸了一切。只要它是硬编码的,它就可以工作。但是,只要它作为 $_email 无处不在,它就不会。该消息作为“更新”通过,但没有更新。

require_once('appVars6.php');
require_once('connectVars6.php');
$_dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$_id = $_GET['id'];
$_queryOne = "SELECT * FROM midterm WHERE id = '$_id'";
$_resultOne = mysqli_query($_dbc, $_queryOne) or die ('Error Querying Database');
while ($_row = mysqli_fetch_array($_resultOne)) {
echo '<form class="update" method="post" action="MT_vjones_udpateRecord.php?id=' . $_id . '">';
echo '<input type="hidden" name="id" id="id" value="' . $_row['id'] . '" />';
echo '<input type="text" name="firstName" id="firstName" value="' . $_row['firstName'] . '" /><br />';
echo '<input type="text" name="lastName" id="lastName" value="' . $_row['lastName'] . '" /><br />';
echo '<input type="text" name="email" id="email" value="' . $_row['email'] . '" /><br />';
echo '</form>';
}
if ( isset($_GET['firstName']) && isset($_GET['lastName']) && isset($_GET['email'])) {
$_id = $_GET['id'];
$_firstName = $_GET['firstName'];
$_lastName = $_GET['lastName'];
$_email = $_GET['email'];   
}
else if ( isset($_POST['firstName']) && isset($_POST['lastName']) && isset($_POST['email'])) {
$_id = $_POST['id'];
$_firstName = mysqli_real_escape_string($_dbc, trim($_POST['firstName']));
$_lastName = mysqli_real_escape_string($_dbc, trim($_POST['lastName']));
$_email = mysqli_real_escape_string($_dbc, trim($_POST['email']));
}
else {
echo '<br />';
echo '<p class="error">Sorry, no record was selected.</p>';
}
if(isset($_POST['submit'])) {
if ($_POST['confirm'] == 'Yes') {
//$_dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$_query = "UPDATE midterm " .
"SET email = '$_email'" .
"WHERE id = $_id" ;
$_result = mysqli_query($_dbc, $_query) or die (mysqli_error($_dbc));
mysqli_close($_dbc);
echo '<p>The record of ' . $_firstName . ' ' . $_lastName . ' for ' . $_email . ' was successfully updated.';
}
else {
echo '<p class="error">The record was not updated.</p>';
}
}
else if (isset($_id) && isset($_firstName) && isset($_lastName) && isset($_email)) {
echo '<p>Are you sure you want to update the following record?</p>';
/*echo '<form class="update" method="post" action="MT_vjones_updateRecord.php">';
echo '<input type="text" name="firstName" id="firstName" value="' . $_firstName . '" /><br />';
echo '<input type="text" name="lastName" id="lastName" value="' . $_lastName . '" /><br />';
echo '<input type="text" name="email" id="email" value="' . $_email . '" /><br />';
echo '</form>';*/
echo '<form class="update" method="post" action="MT_vjones_updateRecord.php?id=' . $_id . '">';
echo '<div class="yesNo"><input class="radio" type="radio" name="confirm" value="Yes" /> Yes </div><br />';
echo '<div class="yesNo"><input class="radio" type="radio" name="confirm" value="No" checked="checked" /> No </div><br /><br />';
echo '<input class="applyBtn" type="submit" value="UPDATE" name="submit" />';
echo '<input type="hidden" name="id" value="' . $_id . '" />';
echo '<input type="hidden" name="firstName" value="' . $_firstName . '" />';
echo '<input type="hidden" name="lastName" value="' . $_lastName . '" />';
echo '<input type="hidden" name="email" value="*testBACK2FUN@test.com*" />';
}
echo '<p><a href="MT_vjones_adminAccess.php">&lt;&lt; Back to the Admin Page</a></p>';

如您所见,我们将电子邮件地址放在那里用于测试目的......

4

4 回答 4

0
  $_query = "UPDATE midterm " .
            "SET email = '$_email' WHERE id = '$_id'" ;

应该

$_query = "UPDATE midterm " .
          "SET email = $_email".
          "WHERE id = $_id " ;
于 2013-03-05T06:04:26.137 回答
0

检查 id 是否与您要更新的内容相匹配。确保在更新之前和之后打印 $_id 和 $_email。

@user710502:您不需要在 PHP 中用双引号分隔引号。无论如何它都会读取它,您唯一可能会打扰的是如果您正在从数组中读取,例如:

"UPATE midterm SET email='".$POST['email']."'"
于 2013-03-05T06:09:59.987 回答
0

原因是您使用的$_before 变量不是有效的变量声明。

因为是为php$_保留的。SUPER GLOBAL(i.e $_SESSION,$_SERVER,$_POST,$_GET,$_COOKIE etc)

如果这对您来说不是问题,那么您需要如下连接您的变量。

$_query = "UPDATE midterm SET email = '".$_email."' WHERE id = '".$_id."'" ;
于 2013-03-05T06:19:55.157 回答
0

解决了!形式问题。

应该:

<?php
require_once('appVars6.php');
require_once('connectVars6.php');

$_dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

$_id = $_GET['id'];
$_queryOne = "SELECT * FROM midterm WHERE id = '$_id'";
$_resultOne = mysqli_query($_dbc, $_queryOne) or die ('Error Querying Database');

while ($_row = mysqli_fetch_array($_resultOne)) {
    echo '<form class="update" method="post" action="MT_vjones_udpateRecord.php?id=' . $_id . '">';
    echo '<input type="hidden" name="id" id="id" value="' . $_row['id'] . '" />';
    echo '<input type="hidden" name="firstName" id="firstName" value="' . $_row['firstName'] . '" />';
    echo '<input type="hidden" name="lastName" id="lastName" value="' . $_row['lastName'] . '" />';
    echo '<input type="hidden" name="email" id="email" value="' . $_row['email'] . '" />';
    echo '</form>';
}

if ( isset($_GET['firstName']) && isset($_GET['lastName']) && isset($_GET['email'])) {
    $_id = $_GET['id'];
    $_firstName = $_GET['firstName'];
    $_lastName = $_GET['lastName'];
    $_email = $_GET['email'];   
}

    else if ( isset($_POST['firstName']) && isset($_POST['lastName']) && isset($_POST['email'])) {
        $_id = $_POST['id'];
        $_firstName = mysqli_real_escape_string($_dbc, trim($_POST['firstName']));
        $_lastName = mysqli_real_escape_string($_dbc, trim($_POST['lastName']));
        $_email = mysqli_real_escape_string($_dbc, trim($_POST['email']));
    }

        else {
                echo '<br />';
                echo '<p class="error">Sorry, no record was selected.</p>';
        }

if(isset($_POST['submit'])) {
    if ($_POST['confirm'] == 'Yes') {

    $_query = "UPDATE midterm " .
                "SET email = '$_email'" .
                "WHERE id = $_id" ;

    $_result = mysqli_query($_dbc, $_query) or die (mysqli_error($_dbc));

    mysqli_close($_dbc);
    echo '<p>The record of ' . $_firstName . ' ' . $_lastName . ' for ' . $_email . ' was successfully updated.';
    }

        else {
            echo '<p class="error">The record was not updated.</p>';
        }
}

    else if (isset($_id) && isset($_firstName) && isset($_lastName) && isset($_email)) {
        echo '<p>Are you sure you want to update the following record?</p>';
        echo '<form class="update" method="post" action="MT_vjones_updateRecord.php?id=' . $_id . '">';
        echo '<div class="yesNo"><input class="radio" type="radio" name="confirm" value="Yes" /> Yes </div><br />';
        echo '<div class="yesNo"><input class="radio" type="radio" name="confirm" value="No" checked="checked" /> No </div><br /><br />';
        echo '<input type="hidden" name="id" value="' . $_id . '" />';
        echo '<input type="text" name="firstName" value="' . $_firstName . '" /><br />';
        echo '<input type="text" name="lastName" value="' . $_lastName . '" /><br />';
        echo '<input type="text" name="email" value="' . $_email . '" />';
        echo '<input class="applyBtn" type="submit" value="UPDATE" name="submit" />';
    }

echo '<p><a href="MT_vjones_adminAccess.php">&lt;&lt; Back to the Admin Page</a></p>';
?>
于 2013-03-06T05:21:28.730 回答