php mysql编辑功能错误提交按钮显示错误

时间:2014-03-23 15:06:28

标签: php mysql

我的系统中有一个错误...当我点击useraccounts来显示系统中用户的信息时,它说:注意:未定义的索引:C:\ xampp \ htdocs \ GuidanceRecord \ useraccounts.php中的用户名第75行 我知道问题很简单,但我看不出问题是什么...... 我的useraccounts.php是:

<?php

$records = mysql_connect('localhost', 'root', '') or die(mysql_error()); 

mysql_select_db('records', $records);

$sql = 'SELECT * FROM login';
$result = mysql_query($sql, $records);

echo "<table border='1' width='100%'>";





while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td width='20%'><img src='image/loginimage2.jpg'></img>";
echo "</td>";
echo $row['Username'];
echo "<td width='15%'><a href='#'>Guidance<br>Administrator</a>";
echo "</td>";
echo "<td>";
echo "<a href='edituser.php?no={$row['ID']}'><input type='button' name='edit' value='Edit' class='btn btn-success'></a>";
echo "</td>";

}

echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
?>

我也有这个名为edituser.php的编辑页面......

<?php
ob_start();
session_start();
?>
<!DOCTYPE html>  
<html>  
  <head>  
    <title>UCC Guidance Record System</title>  
    <link rel="stylesheet" type="text/css" media="all" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="all" href="css/bootstrap-responsive.min.css">
    <link rel="stylesheet" type="text/css" media="all" href="css/global.css">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript"src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/textbox.js"></script>


  </head>  
  <body> 

<?php
$records = mysql_connect("localhost","root","");
mysql_select_db("records",$records);


if(!isset($_POST['savechanges']))
{
$sql = "SELECT * FROM login WHERE ID = $_GET[no]";
$result = mysql_query($sql);
$login = mysql_fetch_array($result);

}














?>
    <div class="container">

    <br>
        <div class="navbar"> 
            <div class="navbar-inner">  
                 <div class="container">
                        <ul class="nav">    
                            <li><a href="viewrecords.php">View Records</a></li>
                            <li><a href="addrecords.php">Add Records</a></li>
                            <li class="active"><a href="useraccounts.php">User Accounts</a></li>
                        </ul>
                        <span class="span6">

                        </span>
                        <ul class="nav">    
                            <li><a href="#">Logout</a></li>
                        </ul>
                 </div>
            </div>  
        </div> 



            <div class="row">
            <span class="span12">
            <img src="image/UCC Guidance Record System2.png" width="100%" height="210px"></img>
            </span>
                    <span class="span2">
                </span>


                <span class="span8">    
                    <br><br>



    <table border="0" width="100%" height="100%">

                    <tr>
                        <td width="33%">
                        <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                        </td>
                        <td width="33%">
                        </td>
                        <td width="33%">
                        </td>
                    </tr>
                    <tr>
                        <td width="33%">
                        User Accounts
                        </td>
                        <td width="33%">
                        </td>
                        <td width="33%">
                        </td>
                    </tr>
                    <tr>
                        <td width="33%">
                        Username:
                        </td>
                        <td width="33%">
                        Password:
                        </td>
                        <td width="33%">
                        </td>
                    </tr>
                    <tr>
                        <td width="33%">
                            <input type="hidden" name="ID" value="<?php echo $login['ID']; ?>" />
                            <input type="text" name="Username" title="Username" style="color:#888;" value="<?php echo $login['Username']; ?>" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
                        </td>
                        <td width="33%">
                            <input type="Password" name="Password" title="Password" style="color:#888;" value="<?php echo $login['Password']; ?>" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
                        </td>
                        <td width="33%">
                        </td>
                    </tr>

                    <tr>
                        <td width="33%">
                        </td>
                        <td width="33%">
                        </td>
                        <td width="33%">
                        <input type="submit" name="savechanges" class="btn btn-primary" value="Save Changes">
                        </form>
                        </td>
                    </tr>
    </table>




                </span> 
    </div>

    <div class="container"> 
        <ul class="pager container-fluid">  
            <li class="pull-left"><a href="addrecords.php">Previous</a></li>
            <li class="pull-right"><a href="#">Next</a></li>  
        </ul>
    </div>  
    </div>
    <center><small class="muted">UCC Guidance Record System<br>
    Developed by Christian Baltazar and Jocella Barruga.<br>
    Copyright 2014.</small></center>

<?php
if(isset($_POST['savechanges']))
{
$id = $_POST['ID'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];

$update = "UPDATE students ".
       "SET Username = '$Username' ".
       ", Password = '$Password' ".
       "WHERE ID = $id" ;

mysql_query($update) or die(mysql_error());

echo "User has been modified!";
header("Location: http://localhost/GuidanceRecord/Useraccounts.php");
exit() ;
}
?>
  </body>  
</html>  

我还有一个名为“records”的数据库,名为“login”的表和名为“ID”,“Username”和“Password”的列...... 我是php的新手......希望你明白...... 在此先感谢答案......:))

3 个答案:

答案 0 :(得分:0)

试试这个

$row = mysql_fetch_array($result,MYSQL_ASSOC)

而不是

$row = mysql_fetch_array($result)

并且也不推荐使用mysql,并且非常容易受到sql注入使用PDO或Mysqli的攻击。<​​/ p>

答案 1 :(得分:0)

您确定在数据库中调用了您的列名称&#39;用户名&#39 ;?它可能是&#39;用户名&#39;,因为你知道PHP是字符敏感的。

尝试运行print_r以查看从数据库中获取的内容:

echo '<pre>'; print_r($row); echo '</pre>';

答案 2 :(得分:0)

在您在锚点链接中输出id时,尝试将“ID”替换为0,它指定要显示的列号。