Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL:更改列中的值_Php_Sql_Undefined Index - Fatal编程技术网

Php MySQL:更改列中的值

Php MySQL:更改列中的值,php,sql,undefined-index,Php,Sql,Undefined Index,这个头衔几乎可以说是诚实的。我正在尝试将删除列从0更改为1,具体取决于从我的ListPlayer下拉列表中选择的播放器 <?php include "dbconnect.php"; //Opening Database Connection $sql = "SELECT * FROM `players` WHERE `Delete` = 0;"; if (!$result = mysql_query($sql, $conn)) { die('Error in querying

这个头衔几乎可以说是诚实的。我正在尝试将删除列从0更改为1,具体取决于从我的ListPlayer下拉列表中选择的播放器

<?php
include "dbconnect.php"; //Opening Database Connection

$sql = "SELECT * FROM `players` WHERE `Delete` = 0;";

if (!$result = mysql_query($sql, $conn))
{
    die('Error in querying the database' . mysql_error());
}

echo "<br><select name = 'listPersons' id = 'listPersons' onclick = 'populate()'>";

while ($row = mysql_fetch_array($result))
{
    $id = $row['playersID'];
    $pName = $row['playersName'];
    $dob = $row['playersDateOfBirth'];
    $dob = date  ("d-m-Y", strtotime($dob));

    $allText = "$id, $pName, $dob";
    echo "<option value = '$allText'> $pName </option>";
}

echo "</select>";
mysql_close($conn);
?>
我的listPlayers.php文件100%正常工作。球员们在比赛中表现良好。我应该补充一点,错误发生在我的$sql变量中

最后是我的listPlayers.php,它在下拉列表中显示我的球员姓名

<?php
include "dbconnect.php"; //Opening Database Connection

$sql = "SELECT * FROM `players` WHERE `Delete` = 0;";

if (!$result = mysql_query($sql, $conn))
{
    die('Error in querying the database' . mysql_error());
}

echo "<br><select name = 'listPersons' id = 'listPersons' onclick = 'populate()'>";

while ($row = mysql_fetch_array($result))
{
    $id = $row['playersID'];
    $pName = $row['playersName'];
    $dob = $row['playersDateOfBirth'];
    $dob = date  ("d-m-Y", strtotime($dob));

    $allText = "$id, $pName, $dob";
    echo "<option value = '$allText'> $pName </option>";
}

echo "</select>";
mysql_close($conn);
?>
对不起,这篇文章比较长。我通常能够修复99%的未定义错误。这个让我迷路了


干杯

使用禁用的文本框为用户显示它

使用另一个隐藏字段保存playerId

用脚本填充这两个字段,然后在需要删除时可以使用隐藏字段中的值

为清晰起见,我将向您展示HTML的外观-以下是脚本:

<script>
    function populate()
    {
        var select = document.getElementById("listPersons"); 
        var result = select.options[select.selectedIndex].value;

        var personDetails = result.split(", ");
        document.getElementById("playersID_display").value = personDetails[0];
        document.getElementById("playersID").value = personDetails[0];
        document.getElementById("pName_display").value = personDetails[1];
        document.getElementById("pName").value = personDetails[1];
....
以及html:

<form name = "myForm" action = "deletePlayer.php" method = "POST">    
    <p>
        <label for> Players ID:
            <input type = "text" name = "playersID_display" id = "playersID_display" disabled/>
            <input type = "hidden" name = "playersID" id = "playersID" />
        </label>
    </p>

    <p>
        <label for> Players Name:
            <input type = "text" name = "pName_display" id = "pName_display" disabled/>
            <input type = "hidden" name = "pName" id = "pName" />
        </label>
    </p>

    <p>
        <label for> Date of Birth:
            <input type = "date" name = "DoB_display" id = "DoB_display" disabled/>
            <input type = "hidden" name = "DoB" id = "DoB" />
        </label>
    </p>

    <input type = "Submit" value = "Delete" class = "button" onClick = "return confirm('Are you sure you want to delete this player?')"/>

</form>     
注意,我维护了字段的唯一名称和HTML输入元素的唯一ID。我也更喜欢type=hidden,而不是将hidden放在元素的末尾——我不熟悉这种语法,所以我使用我喜欢的方式


显然,您的脚本必须单独更新这些字段。

这可能是因为我的PlayerId文本框被禁用了吗?-在没有残疾人的情况下尝试一下,看看你会得到什么样的结果。它可以工作,但不允许编辑文本框。我可以让文本框保持启用状态,但仍然不允许用户编辑它们吗?您可以始终尝试使用隐藏属性。我会使用隐藏属性,但当我在listPlayers下拉列表中选择一个播放机时,在进行删除之前,播放机数据将显示在相应的文本框中。很不幸,隐藏在这种情况下是行不通的。好的,好主意。我现在已经写出来了,所以我有两个输入框,如下所示。但是当我单击delete时,我的sql语法中出现了一个错误。第1行上的问题。但是第一行有我的开始php标签 玩家ID:

当SQL报告错误时,它不是脚本中的行,而是SQL查询中的行。您得到的具体错误是什么?您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解第1行附近使用的正确语法。它在deletePlayer.php文件中显示此错误。我在回答中没有提及此错误,但MySQL_*已被弃用-您确实应该在准备语句中使用mysqli_*或PDO。哪个查询导致此错误?哪一个脚本-我在你的问题中发布的各种脚本之间迷失了方向。。。