PHP 代码正在获取,只是没有像以前那样获取 ID,所以它没有正确更新

发布于 2025-01-07 04:27:00 字数 12470 浏览 3 评论 0原文

我重写了代码以尽可能多地分解 PHP 和 html,老实说,我认为它看起来很难看,但这里的人们似乎认为这是很好的做法。

无论如何,下拉菜单仍然是所有 PHP 语言,因为我不知道如何用 html 编写它。

无论如何,如果有人能为我做到这一点那就太好了,但现在这是我真正的问题。一切都表明......我只是无法发帖,而且我不明白为什么。这是代码和错误:

<?php
require_once('tb/connectvars.php');
echo '<div id="postwrap">';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>PDI NCMR - Edit</title>
  <link rel="stylesheet" type="text/css" href="tb/postie.css" />
</head>
<body>
   <div id="logo">
    <img src="../images/PDI_Logo_2.1.gif" alt="PDI Logo" />
</div>

<?php
  if (isset($_POST['submit'])) {
// Connect to the database
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
;   
// Enter data into the database
    $id = mysqli_real_escape_string($dbc, trim($_GET['id']));
    $ab = mysqli_real_escape_string($dbc, trim($_POST['ab']));
    $date = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime ($_POST['date']))));
    $part = mysqli_real_escape_string($dbc, trim($_POST['part']));
    $rev = mysqli_real_escape_string($dbc, trim($_POST['rev']));
    $partdesc = mysqli_real_escape_string($dbc, trim($_POST['partdesc']));
    $ncmrqty = mysqli_real_escape_string($dbc, trim($_POST['ncmrqty']));
    $comp = mysqli_real_escape_string($dbc, trim($_POST['comp']));
    $ncmrid = mysqli_real_escape_string($dbc, trim($_POST['ncmrid']));
    $rma = mysqli_real_escape_string($dbc, trim($_POST['rma']));
    $jno = mysqli_real_escape_string($dbc, trim($_POST['jno']));
    $fdt = mysqli_real_escape_string($dbc, trim($_POST['fdt']));
    $cof = mysqli_real_escape_string($dbc, trim($_POST['cof']));
    $fab1= mysqli_real_escape_string($dbc, trim($_POST['fab1']));
    $fab2= mysqli_real_escape_string($dbc, trim($_POST['fab2']));
    $fab3= mysqli_real_escape_string($dbc, trim($_POST['fab3']));
    $non= mysqli_real_escape_string($dbc, trim($_POST['non']));
    $dis= mysqli_real_escape_string($dbc, trim($_POST['dis']));
    $comm= mysqli_real_escape_string($dbc, trim($_POST['comm']));
    $caad= mysqli_real_escape_string($dbc, trim($_POST['caad']));
    $po= mysqli_real_escape_string($dbc, trim($_POST['po']));
    $pod = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime($_POST['pod']))));
    $dri = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime($_POST['dri']))));

    $query = "UPDATE ncmr SET ab = '$ab', date = '$date', part = '$part', rev = '$rev' , partdesc = '$partdesc' , ncmrqty = '$ncmrqty' , comp = '$comp' , ncmrid = '$ncmrid' , rma = '$rma' , jno = '$jno' , fdt = '$fdt' , cof = '$cof' , fab1 = '$fab1' , fab2 = '$fab2' , fab3 = fab3' , non = '$non' , dis = '$dis' , comm = '$comm' , caad = '$caad' , po = '$po' , pod = '$pod' , dri = '$dri'  WHERE id = '$id'";

// echo your raw query and look for obvious errors
     echo "Query is : " . $query . "<br />";

// and at least use a basic mechanism to trap possibles errors
       mysqli_query($dbc, $query)  or die('Query Error : ' . mysqli_error($dbc));

// Clear the data to clear the form
    $id = "";
    $ab = "";
    $date = "";
    $part = "";
    $rev = "";
    $partdesc = "";
    $ncmrqty = "";
    $comp = "";
    $ncmrid = "";
    $rma = "";
    $jno = "";
    $fdt = "";
    $cof = "";
    $fab1= "";
    $fab2= "";
    $fab3= "";
    $non= "";
    $dis= "";
    $comm= "";
    $caad= "";
    $po= "";
    $pod = "";
    $dri = "";

// Confirm success with the user
        echo '<p>If you wish to edit more NCMRs, please <a href="list.php">go to the admin page!</a></p>';

            mysqli_close($dbc);
            }

  else {    

// Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Grab the profile data from the database
 if (!isset($_GET['id'])) {
    $query = "SELECT * FROM ncmr WHERE id = '$id'";
  }
  else {
    $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'";
  }
  $data = mysqli_query($dbc, $query);

  if (mysqli_num_rows($data) == 1) { 
// The user row was found so display the user data
    $row = mysqli_fetch_array($data);
    echo'<div id="title"><h3 id="NCMR2">Non-Conforming Materials Report (NCMR:&nbsp;&nbsp;' . $row['rma'] . ')</h3></div>';

    if (empty($row['ab'])) $row['ab'] == "Empty";
    if (empty($row['date'])) $row['date'] == "Empty";
    if (empty($row['part'])) $row['part'] == "Empty";
    if (empty($row['rev'])) $row['rev'] == "Empty";
    if (empty($row['partdesc'])) $row['partdesc'] = "Empty";
    if (empty($row['ncmrqty'])) $row['ncmrqty'] = "Empty";
    if (empty($row['comp'])) $row['comp'] == "Empty";
    if (empty($row['ncmrid'])) $row['ncmrid'] == "Empty";
    if (empty($row['rma'])) $row['rma'] == "Empty";
    if (empty($row['jno'])) $row['jno'] == "Empty";
    if (empty($row['non'])) $row['non'] == "Empty";
    if (empty($row['dis'])) $row['dis'] == "Empty";
    if (empty($row['comm'])) $row['comm'] == "Empty";
    if (empty($row['caad'])) $row['caad'] == "Empty";
    if (empty($row['po'])) $row['po'] =="Empty";
    if (empty($row['pod'])) $row['pod'] =="Empty";
    if (empty($row['dir'])) $row['dri'] =="Empty";

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <fieldset>
        <div id="box1">
            <div id="ab"><span class="b">Added By:&nbsp;&nbsp;</span><input type="text" name="ab" value="<?php echo $row['ab']?>" /></div>
            <div id="date"><span class="b">Date Filed:&nbsp;&nbsp;</span><input type="text" name="date" value="<?php echo $row['date']?>" /></div>
            <div id="part"><span class="b">Part Number:&nbsp;&nbsp;</span><input type="text" name="part" value="<?php echo $row['part']?>" /></div>
            <div id="rev"><span class="b">Part Revision:&nbsp;&nbsp;</span><input type="text" name="rev" value="<?php echo $row['rev']?>" /></div>
            <div id="partdesc"><span class="b">Part Description:&nbsp;&nbsp;</span><textarea rows="4" cols="22" value=><?php echo $row['partdesc']?></textarea></div>
            <div id="ncmrqty"><span class="b">NCMR Qty:&nbsp;&nbsp;</span><input type="text" name="ncmrqty" value="<?php echo $row['ncmrqty']?>"/></div>    
        </div>

        <div id="box2">
            <div id="comp"><span class="b">Company:&nbsp;&nbsp;</span><input type="text" name="comp" value="<?php echo $row['comp']?>" /></div>
            <div id="ncmrid"><span class="b">Customer NCMR ID:&nbsp;&nbsp;</span><input type="text" name="ncmrid" value="<?php echo $row['ncmrid']?>" /></div>
            <div id="rma"><span class="b">Internal RMA #:&nbsp;&nbsp;</span><input type="text" name="rma" value="<?php echo $row['rma']?>" /></div>
            <div id="jno"><span class="b">Job #:&nbsp;&nbsp;</span><input type="text" name="jno" value="<?php echo $row['jno']?>" /></div>
        </div>

        <div id="box3">
            <h2>Failure</h2>
                <div id="cof"><span class="b">Class of Failure:&nbsp;&nbsp;</span><input type="text" name="cof" size="15" value="<?php echo $row['cof']?>" /></div>
                <div id="fdt"><span class="b">Failure Due To:&nbsp;&nbsp;</span><input type="text" name="fdt" size="15" value="<?php echo $row['fdt']?>" /></div>
        </div>
<?php
        echo '<div id="box4">';
            echo '<h2>Fabricators</h2>';
if ($row['fab1']=="--None--")
{
    echo'<div id="fab1">';
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
    $mysqli->select_db('user');
    $result = $mysqli->query("SELECT * FROM user"); 
    echo "<SELECT name='fab1'>\n";
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['userid']}'>{$row['user']}</option>\n";
    }
    echo "</select>\n";
    echo '</div>';
}
else
{
    echo '<div id="fab1"><span class="b"></span><input type="text" name="fab1"  size="20" value="' . $row['fab1'] . '" /></div>';
}

if ($row['fab2']=="--None--")
{
    echo'<div id="fab1">';
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
    $mysqli->select_db('user');
    $result = $mysqli->query("SELECT * FROM user"); 
    echo "<SELECT name='fab2'>\n";
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['userid']}'>{$row['user']}</option>\n";
    }
    echo "</select>\n";
    echo '</div>';
}
else
{
    echo '<div id="fab2"><span class="b"></span><input type="text" name="fab2"  size="20" value="' . $row['fab2'] . '" /></div>';
}
if ($row['fab3']=="--None--")
{
    echo'<div id="fab3">';
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
    $mysqli->select_db('user');
    $result = $mysqli->query("SELECT * FROM user"); 
    echo "<SELECT name='fab3'>\n";
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['userid']}'>{$row['user']}</option>\n";
    }
    echo "</select>\n";
    echo '</div>';
}
else
{
    echo '<div id="fab3"><span class="b"></span><input type="text" name="fab3"  size="20" value="' . $row['fab3'] . '" /></div>';
}
echo '</div>';
?>
        <div id="box5">
            <div id="non"><span class="b">Nonconformity:&nbsp;&nbsp;</span><textarea rows="4" cols="105" value=><?php echo $row['non']?></textarea></div>
            <div id="dis"><span class="b">Disposition:&nbsp;&nbsp;</span><textarea rows="4" cols="105" value=><?php echo $row['dis']?></textarea></div>
            <div id="comm"><span class="b">Comments:&nbsp;&nbsp;</span><textarea rows="4" cols="105" value=><?php echo $row['comm']?></textarea></div>
            <div id="caad"><span class="b">Comments and/or Additional Details:&nbsp;&nbsp;</span><textarea rows="4" cols="105" value=><?php echo $row['caad']?></textarea></div>
        </div>

        <div id="podr">
        <div id="po"><span class="b">PO:&nbsp;&nbsp;</span><input type="text" name="po"  size="7" value="<?php echo $row['po']?>" /></div>
        <div id="pod"><span class="b">PO Date:&nbsp;&nbsp;</span><input type="text" name="pod"  size="7" value="<?php echo $row['pod']?>" /></div>
        <div id="dri"><span class="b">Date Received:&nbsp;&nbsp;</span><input type="text" name="dri"  size="7" value="<?php echo $row['dri']?>" /></div>
        </div>
            <div id="button2"><input type="submit" value="Submit Edits" name="submit" /></div>
        </div>
    </fieldset>
</form>
<?php
        }
    }


echo '</div>';
?>

错误是这样的:

查询为:UPDATE ncmr SET ab = 'Matt Ridge',日期 = '2012-01-09',part = 'K17212191',rev = '01',partdesc = '',ncmrqty = '2',comp = '查尔斯河实验室', ncmrid = '1243', rma = '空' , jno = '空' , fdt = '第三方' , cof = '材料' , fab1 = '安迪·卡尔' , fab2 = '安东尼·阿尤布' , fab3 = fab3' , non = '' , dis = ' '、comm = ''、caad = ''、po = '1'、 pod = '2011-01-01',dri = '2011-01-03' 其中 id = ''

查询错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '' 、 non = '' 、 dis = '' 、 comm = '' 、 caad = '' 、 po = '1' 、 pod = '2011 附近使用的正确语法-01-01' ' 在第 1 行

它没有再次提取 ID,我以为我用之前的代码修复了这个问题,但似乎没有。如果有人能给我一点帮助,我将不胜感激。

I've rewritten the code to break up as much PHP and html as possible, Honestly I thin it looks ugly, but people here seem to think it is good practise.

In any case, the drop down menus are still in all PHP because I couldn't figure out how to write it in html.

In any case if anyone can do that for me great, but here is my real problem now. Everything shows... I just can't post, and I can't figure out why. Here is the code, and the errors:

<?php
require_once('tb/connectvars.php');
echo '<div id="postwrap">';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>PDI NCMR - Edit</title>
  <link rel="stylesheet" type="text/css" href="tb/postie.css" />
</head>
<body>
   <div id="logo">
    <img src="../images/PDI_Logo_2.1.gif" alt="PDI Logo" />
</div>

<?php
  if (isset($_POST['submit'])) {
// Connect to the database
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
;   
// Enter data into the database
    $id = mysqli_real_escape_string($dbc, trim($_GET['id']));
    $ab = mysqli_real_escape_string($dbc, trim($_POST['ab']));
    $date = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime ($_POST['date']))));
    $part = mysqli_real_escape_string($dbc, trim($_POST['part']));
    $rev = mysqli_real_escape_string($dbc, trim($_POST['rev']));
    $partdesc = mysqli_real_escape_string($dbc, trim($_POST['partdesc']));
    $ncmrqty = mysqli_real_escape_string($dbc, trim($_POST['ncmrqty']));
    $comp = mysqli_real_escape_string($dbc, trim($_POST['comp']));
    $ncmrid = mysqli_real_escape_string($dbc, trim($_POST['ncmrid']));
    $rma = mysqli_real_escape_string($dbc, trim($_POST['rma']));
    $jno = mysqli_real_escape_string($dbc, trim($_POST['jno']));
    $fdt = mysqli_real_escape_string($dbc, trim($_POST['fdt']));
    $cof = mysqli_real_escape_string($dbc, trim($_POST['cof']));
    $fab1= mysqli_real_escape_string($dbc, trim($_POST['fab1']));
    $fab2= mysqli_real_escape_string($dbc, trim($_POST['fab2']));
    $fab3= mysqli_real_escape_string($dbc, trim($_POST['fab3']));
    $non= mysqli_real_escape_string($dbc, trim($_POST['non']));
    $dis= mysqli_real_escape_string($dbc, trim($_POST['dis']));
    $comm= mysqli_real_escape_string($dbc, trim($_POST['comm']));
    $caad= mysqli_real_escape_string($dbc, trim($_POST['caad']));
    $po= mysqli_real_escape_string($dbc, trim($_POST['po']));
    $pod = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime($_POST['pod']))));
    $dri = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime($_POST['dri']))));

    $query = "UPDATE ncmr SET ab = '$ab', date = '$date', part = '$part', rev = '$rev' , partdesc = '$partdesc' , ncmrqty = '$ncmrqty' , comp = '$comp' , ncmrid = '$ncmrid' , rma = '$rma' , jno = '$jno' , fdt = '$fdt' , cof = '$cof' , fab1 = '$fab1' , fab2 = '$fab2' , fab3 = fab3' , non = '$non' , dis = '$dis' , comm = '$comm' , caad = '$caad' , po = '$po' , pod = '$pod' , dri = '$dri'  WHERE id = '$id'";

// echo your raw query and look for obvious errors
     echo "Query is : " . $query . "<br />";

// and at least use a basic mechanism to trap possibles errors
       mysqli_query($dbc, $query)  or die('Query Error : ' . mysqli_error($dbc));

// Clear the data to clear the form
    $id = "";
    $ab = "";
    $date = "";
    $part = "";
    $rev = "";
    $partdesc = "";
    $ncmrqty = "";
    $comp = "";
    $ncmrid = "";
    $rma = "";
    $jno = "";
    $fdt = "";
    $cof = "";
    $fab1= "";
    $fab2= "";
    $fab3= "";
    $non= "";
    $dis= "";
    $comm= "";
    $caad= "";
    $po= "";
    $pod = "";
    $dri = "";

// Confirm success with the user
        echo '<p>If you wish to edit more NCMRs, please <a href="list.php">go to the admin page!</a></p>';

            mysqli_close($dbc);
            }

  else {    

// Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Grab the profile data from the database
 if (!isset($_GET['id'])) {
    $query = "SELECT * FROM ncmr WHERE id = '$id'";
  }
  else {
    $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'";
  }
  $data = mysqli_query($dbc, $query);

  if (mysqli_num_rows($data) == 1) { 
// The user row was found so display the user data
    $row = mysqli_fetch_array($data);
    echo'<div id="title"><h3 id="NCMR2">Non-Conforming Materials Report (NCMR:  ' . $row['rma'] . ')</h3></div>';

    if (empty($row['ab'])) $row['ab'] == "Empty";
    if (empty($row['date'])) $row['date'] == "Empty";
    if (empty($row['part'])) $row['part'] == "Empty";
    if (empty($row['rev'])) $row['rev'] == "Empty";
    if (empty($row['partdesc'])) $row['partdesc'] = "Empty";
    if (empty($row['ncmrqty'])) $row['ncmrqty'] = "Empty";
    if (empty($row['comp'])) $row['comp'] == "Empty";
    if (empty($row['ncmrid'])) $row['ncmrid'] == "Empty";
    if (empty($row['rma'])) $row['rma'] == "Empty";
    if (empty($row['jno'])) $row['jno'] == "Empty";
    if (empty($row['non'])) $row['non'] == "Empty";
    if (empty($row['dis'])) $row['dis'] == "Empty";
    if (empty($row['comm'])) $row['comm'] == "Empty";
    if (empty($row['caad'])) $row['caad'] == "Empty";
    if (empty($row['po'])) $row['po'] =="Empty";
    if (empty($row['pod'])) $row['pod'] =="Empty";
    if (empty($row['dir'])) $row['dri'] =="Empty";

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <fieldset>
        <div id="box1">
            <div id="ab"><span class="b">Added By:  </span><input type="text" name="ab" value="<?php echo $row['ab']?>" /></div>
            <div id="date"><span class="b">Date Filed:  </span><input type="text" name="date" value="<?php echo $row['date']?>" /></div>
            <div id="part"><span class="b">Part Number:  </span><input type="text" name="part" value="<?php echo $row['part']?>" /></div>
            <div id="rev"><span class="b">Part Revision:  </span><input type="text" name="rev" value="<?php echo $row['rev']?>" /></div>
            <div id="partdesc"><span class="b">Part Description:  </span><textarea rows="4" cols="22" value=><?php echo $row['partdesc']?></textarea></div>
            <div id="ncmrqty"><span class="b">NCMR Qty:  </span><input type="text" name="ncmrqty" value="<?php echo $row['ncmrqty']?>"/></div>    
        </div>

        <div id="box2">
            <div id="comp"><span class="b">Company:  </span><input type="text" name="comp" value="<?php echo $row['comp']?>" /></div>
            <div id="ncmrid"><span class="b">Customer NCMR ID:  </span><input type="text" name="ncmrid" value="<?php echo $row['ncmrid']?>" /></div>
            <div id="rma"><span class="b">Internal RMA #:  </span><input type="text" name="rma" value="<?php echo $row['rma']?>" /></div>
            <div id="jno"><span class="b">Job #:  </span><input type="text" name="jno" value="<?php echo $row['jno']?>" /></div>
        </div>

        <div id="box3">
            <h2>Failure</h2>
                <div id="cof"><span class="b">Class of Failure:  </span><input type="text" name="cof" size="15" value="<?php echo $row['cof']?>" /></div>
                <div id="fdt"><span class="b">Failure Due To:  </span><input type="text" name="fdt" size="15" value="<?php echo $row['fdt']?>" /></div>
        </div>
<?php
        echo '<div id="box4">';
            echo '<h2>Fabricators</h2>';
if ($row['fab1']=="--None--")
{
    echo'<div id="fab1">';
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
    $mysqli->select_db('user');
    $result = $mysqli->query("SELECT * FROM user"); 
    echo "<SELECT name='fab1'>\n";
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['userid']}'>{$row['user']}</option>\n";
    }
    echo "</select>\n";
    echo '</div>';
}
else
{
    echo '<div id="fab1"><span class="b"></span><input type="text" name="fab1"  size="20" value="' . $row['fab1'] . '" /></div>';
}

if ($row['fab2']=="--None--")
{
    echo'<div id="fab1">';
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
    $mysqli->select_db('user');
    $result = $mysqli->query("SELECT * FROM user"); 
    echo "<SELECT name='fab2'>\n";
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['userid']}'>{$row['user']}</option>\n";
    }
    echo "</select>\n";
    echo '</div>';
}
else
{
    echo '<div id="fab2"><span class="b"></span><input type="text" name="fab2"  size="20" value="' . $row['fab2'] . '" /></div>';
}
if ($row['fab3']=="--None--")
{
    echo'<div id="fab3">';
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
    $mysqli->select_db('user');
    $result = $mysqli->query("SELECT * FROM user"); 
    echo "<SELECT name='fab3'>\n";
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['userid']}'>{$row['user']}</option>\n";
    }
    echo "</select>\n";
    echo '</div>';
}
else
{
    echo '<div id="fab3"><span class="b"></span><input type="text" name="fab3"  size="20" value="' . $row['fab3'] . '" /></div>';
}
echo '</div>';
?>
        <div id="box5">
            <div id="non"><span class="b">Nonconformity:  </span><textarea rows="4" cols="105" value=><?php echo $row['non']?></textarea></div>
            <div id="dis"><span class="b">Disposition:  </span><textarea rows="4" cols="105" value=><?php echo $row['dis']?></textarea></div>
            <div id="comm"><span class="b">Comments:  </span><textarea rows="4" cols="105" value=><?php echo $row['comm']?></textarea></div>
            <div id="caad"><span class="b">Comments and/or Additional Details:  </span><textarea rows="4" cols="105" value=><?php echo $row['caad']?></textarea></div>
        </div>

        <div id="podr">
        <div id="po"><span class="b">PO:  </span><input type="text" name="po"  size="7" value="<?php echo $row['po']?>" /></div>
        <div id="pod"><span class="b">PO Date:  </span><input type="text" name="pod"  size="7" value="<?php echo $row['pod']?>" /></div>
        <div id="dri"><span class="b">Date Received:  </span><input type="text" name="dri"  size="7" value="<?php echo $row['dri']?>" /></div>
        </div>
            <div id="button2"><input type="submit" value="Submit Edits" name="submit" /></div>
        </div>
    </fieldset>
</form>
<?php
        }
    }


echo '</div>';
?>

The error is this:

Query is : UPDATE ncmr SET ab = 'Matt Ridge', date = '2012-01-09', part = 'K17212191', rev = '01' , partdesc = '' , ncmrqty = '2' , comp = 'Charles River Labs' , ncmrid = '1243' , rma = 'Empty' , jno = 'Empty' , fdt = 'Third Party' , cof = 'Materials' , fab1 = 'Andy Kahl' , fab2 = 'Anthony Ayoub' , fab3 = fab3' , non = '' , dis = '' , comm = '' , caad = '' , po = '1' , pod = '2011-01-01' , dri = '2011-01-03' WHERE id = ''

Query Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' , non = '' , dis = '' , comm = '' , caad = '' , po = '1' , pod = '2011-01-01' ' at line 1

It is not pulling the ID again, I thought I fixed this with the code before, but it seems not. If anyone can give me a bit of help it would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淑女气质 2025-01-14 04:27:00

您的代码存在一些问题,您应该首先修复。

例如,不要在 if 语句中使用 = 进行比较,例如

if ($row['fab3']="--None--")

条件将始终评估为 true,因为您正在执行赋值而不是比较。正确的方法:

if ($row['fab3'] == "--None--")

在同一个块中,您再次使用变量 $row 来达到不同的目的:

if ($row['fab3']="--None--")
{
    // [...]
    // assigning $row with something different
    // use a different variable like $row2 here
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['user']}'>{$row['user']}</option>\n";
    }
    // [...]
}
// $row from now on contains the last tuple you fetched inside the above while-loop

请告诉我们这是否可以解决您的问题。

一个不相关的建议:不要将 php 和 html 混合在一个文件中。使用模板引擎,例如 Smarty

编辑1

我建议查看此块中的变量 $query 。

  if (!isset($_GET['id'])) {
    $query = "SELECT * FROM ncmr WHERE id = '$id'";
  }
  else {
    $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'";
  }
  $data = mysqli_query($dbc, $query);

  if (mysqli_num_rows($data) == 1) { 
// The user row was found so display the user data
    $row = mysqli_fetch_array($data);

var_dump($查询);并在 phpmyadmin 中执行此查询。如果查询结果是所需的行,则 var_dump 紧随 mysqli_fetch_array 之后的变量 $row。如果它还包含所需的行,只需按照代码和 var_dump 操作,直到找到损坏的行。

There are some issues with your code, you should fix first.

For example don't use = for comparison in if-statements like

if ($row['fab3']="--None--")

The condition will always evaluate to true because you are doing an assignment instead of a comparison. correct way:

if ($row['fab3'] == "--None--")

In the same block you used the variable $row again for a different purpose:

if ($row['fab3']="--None--")
{
    // [...]
    // assigning $row with something different
    // use a different variable like $row2 here
    while($row = $result->fetch_assoc())
    {
        echo "<option value='{$row['user']}'>{$row['user']}</option>\n";
    }
    // [...]
}
// $row from now on contains the last tuple you fetched inside the above while-loop

Let us know if this fixes your problem.

A unrelated suggestion: Don't mix php and html in one file. use a template engine like Smarty.

Edit1

i suggest to look at the variable $query from this block.

  if (!isset($_GET['id'])) {
    $query = "SELECT * FROM ncmr WHERE id = '$id'";
  }
  else {
    $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'";
  }
  $data = mysqli_query($dbc, $query);

  if (mysqli_num_rows($data) == 1) { 
// The user row was found so display the user data
    $row = mysqli_fetch_array($data);

var_dump($query); and execute this query in phpmyadmin. if the query results the desired rows, var_dump the variable $row right after the mysqli_fetch_array. if it also contains the desired rows just follow the code and var_dump until you find a line after which it got corrupted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文