Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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_Mysql - Fatal编程技术网

PHP/MySQL抛出索引错误,但已列出

PHP/MySQL抛出索引错误,但已列出,php,mysql,Php,Mysql,它朝我扔过来了 注意:未定义索引:第16行D:\xampp\htdocs\0100348514\pages\account.php中的用户名 警告:mysql\u查询要求参数1为字符串,资源在第19行的D:\xampp\htdocs\pages\account.php中给出 但在我的数据库中,我有完全相同的“用户名”,但它仍在向我抛出任何想法 那页上的代码 <?php $page = "My Account"; session_start(); include '../inclu

它朝我扔过来了

注意:未定义索引:第16行D:\xampp\htdocs\0100348514\pages\account.php中的用户名

警告:mysql\u查询要求参数1为字符串,资源在第19行的D:\xampp\htdocs\pages\account.php中给出

但在我的数据库中,我有完全相同的“用户名”,但它仍在向我抛出任何想法

那页上的代码

<?php 
 $page = "My Account"; 
 session_start();
 include '../includes/config.php';
?>  
        <div id="searchbar">
                    <form action="search.php" method="get">
                    <input type="text" name="search" />
                    <input type="submit" name="submit" class="btn btn-primary" value="Search" />
                    </form>
                </div>
        </div>      


<?php 
 $username = $_SESSION['username']; 

 $sql = "SELECT * FROM login WHERE username = '$username'"; 
 $result = mysql_query($con, $sql) or die(mysql_error($con)); //run the query 
 $row = mysql_fetch_array($result); 
?> 


<div id="wrapper">

<section id="content" class="shadow">

                        <div id="titlebar">
                        <?php
                        echo $page = '<h1> My ACCOUNT </h1>';
                        ?>
                        </div>
                        <br />


 <?php 
 //user messages 
 if(isset($_SESSION['error'])) //if session error is set 
 { 
 echo '<div class="error">'; 
 echo '<p class="center">' . $_SESSION['error'] . '</p>'; //display error message 
 echo '</div><br />'; 
 unset($_SESSION['error']); //unset session error 
 } 
 elseif(isset($_SESSION['success'])) //if session success is set 
 { 
 echo '<div class="success">'; 
 echo '<p class="center">' . $_SESSION['success'] . '</p>'; //display success message 
 echo '</div><br />'; 
 unset($_SESSION['success']); //unset session success 
 } 
?> 
 <div id='left'>
 <form id="registration" form action="accountprocessing.php" method="post"> 
    <br />
    <fieldset><h1>Update Your Details</h1><br />

         <ol>
             <li>
             <label>Username*</label> <input type="text" name="username" required value="<?php echo $row['username'] ?>" readonly />
             </li>
             <?php 
             //generate drop-down list for state using enum data type and values from database 
             $tableName='member'; 
             $colState='state'; 

             function getEnumState($tableName, $colState) 
             { 
             global $con; //enable database connection in the function 
             $sql = "SHOW COLUMNS FROM $tableName WHERE field='$colState'"; 
            //retrieve enum column 
             $result = mysql_query($con, $sql) or die(mysql_error($con)); 
            //run the query 
             $row = mysql_fetch_array($result); //store the results in a variable named $row 
             $type = preg_replace('/(^enum\()/i', '', $row['Type']); //regular expression to replace the enum syntax with blank space 
             $enumValues = substr($type, 0, -1); //return the enum string 
             $enumExplode = explode(',', $enumValues); //split the enum string into individual values 
             return $enumExplode; //return all the enum individual values 
             } 
             $enumValues = getEnumState('member', 'state'); 
             echo '<select name="state">'; 

             if((is_null($row['state'])) || (empty($row['state']))) //if the state field is NULL or empty 
             { 
             echo "<option value=''>Please select</option>"; //display the 'Please select' message 
             } 
             else 
             { 
             echo "<option value=" . $row['state'] . ">" . $row['state'] . 
            "</option>"; //display the selected enum value 
             } 

             foreach($enumValues as $value) 
             { 
             echo '<option value="' . $removeQuotes = str_replace("'", "", 
            $value) . '">' . $removeQuotes = str_replace("'", "", $value) . '</option>'; //remove the quotes from the enum values 
             } 
             echo '</select><br />'; 
             ?> 
             </li>
             <p>&nbsp;</p> 
             <li>
             <label>Postcode*</label> <input type="text" name="postcode" required value="<?php echo $row['postcode'] ?>"/>
             </li><br /> 
             <li>
             <label>Country*</label> <input type="text" name="country" required value="<?php echo $row['country'] ?>"/>
             </li><br /> 
             <li>
             <label>Phone</label> <input type="text" name="phone" value="<?php echo $row['phone'] ?>"/>
             </li><br /> 
             <li>
             <label>Mobile</label> <input type="text" name="mobile" value="<?php echo $row['mobile'] ?>" />
             </li><br /> 
            <li>
            <label>Email*</label> <input type="email" name="email" required value="<?php echo $row['email'] ?>" />
            </li><br /> 
             <li><label>Gender*</label> 
             <?php 
             //generate drop-down list for gender using enum data type and values from database 
             $tableName='member'; 
             $colGender='gender'; 

             function getEnumGender($tableName, $colGender) 
             { 
             global $con; //enable database connection in the function 
             $sql = "SHOW COLUMNS FROM $tableName WHERE field='$colGender'"; 
            //retrieve enum column 
             $result = mysql_query($con, $sql) or die(mysql_error($con)); 
            //run the query 
             $row = mysql_fetch_array($result); //store the results in a variable named $row 
             $type = preg_replace('/(^enum\()/i', '', $row['Type']); //regular expression to replace the enum syntax with blank space 
             $enumValues = substr($type, 0, -1); //return the enum string 
             $enumExplode = explode(',', $enumValues); //split the enum string into individual values 
             return $enumExplode; //return all the enum individual values 
             } 

             $enumValues = getEnumGender('member', 'gender'); 
             echo '<select name="gender">'; 

             echo "<option value=" . $row['gender'] . ">" . $row['gender'] . 
            "</option>"; //display the selected enum value 
            foreach($enumValues as $value) 
             { 
             echo '<option value="' . $removeQuotes = str_replace("'", "", 
            $value) . '">' . $removeQuotes = str_replace("'", "", $value) . '</option>'; 
             } 
             echo '</select>'; 
             ?> 
             </li>
        </ol>
    </fieldset>
    <br />
    <fieldset> 
         <p>Subscribe to weekly email newsletter?</p><br /> 
         <label>Yes</label><input type="radio" name="newsletter" value="Y" <?php if($row['newsletter'] == "Y"){echo "checked";} ?>><br /> 
         <label>No</label><input type="radio" name="newsletter" value="N" <?php if($row['newsletter'] == "N"){echo "checked";} ?>>
         <input type="hidden" name="memberID" value="<?php echo $memberID; ?>"> 
         </fieldset><br />
         <p class="center"><input type="submit" name="accountupdate" value="Update Account" /></p><br />
</form>
</div>

<br />
    <div id='right'>
        <form id="registration" form action="accountimageprocessing.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="memberID" value="<?php echo $memberID; ?>"> 
    <br />
            <fieldset><h1>Update Image</h1><br />

             <?php 
             if((is_null($row['image'])) || (empty($row['image']))) //if the photo field is NULL or empty 
             { 
             echo "<p class='center'><img src='../images/members/member.png' width=150 height=150 alt='default photo' /></p>"; //display the default photo 
             } 
             else 
             { 
             echo "<p class='center'><img src='../images/members/" . ($row['image']) . "'" . 'width=150 height=150 alt="contact photo"' . "/></p><br />"; //display the contact photo
            } 
             ?> 

            <label>New Image</label> <input type="file" name="image" />
            <br /> 
            <p>Accepted files are JPG, GIF or PNG. Maximum size is 500kb.</p>
            <br /> 
            <p class='center'><input type="submit" name="imageupdate" value="Update Image" /></p>
        </form>
        <br />
        <br />
            <form action="accountpasswordprocessing.php" method="post"> 
             <h1>Update Password</h1> 
             <br />
             <p>Passwords must have a minimum of 8 characters.</p> <br />
             <label>New Password*</label> <input type="password" name="password" pattern=".{8,}" title= "Password must be 8 characters or more" required />
             <br /> 
             <input type="hidden" name="memberID" value="<?php echo $memberID; ?>"> 
             <br />
             <p class='center'><input type="submit" name="passwordupdate" value="Update Password" /></p> 
             <br />
            </form>

            <h1>Delete My Account</h1>
            <br />
            <p>We're sorry to hear you'd like to delete your account. By clicking the button below you will permanently delete your account.</p>
            <br />
            <form action="accountdelete.php" method="post"> 
            <p class='center'><input type="submit" value="Delete My Account" onclick="return confirm('Are you sure you wish to permanently delete your account?');" ></p> 

            <input type="hidden" name="memberID" value="<?php echo $memberID; ?>"><br />    
        </fieldset>
         </form>
         </div>

        </section> <!-- end #content --> 
        <div id="footernav" class id="shadow">
                                <?php 
                                    require "../inc/footer.php"; 
                                ?>
                            </div>
         </div>
您的参数是反向的。应该是:

mysql_query($sql, $con);
此外,正如您在链接的PHP手册页面中所看到的,此扩展已被弃用,应使用以下替代方法:

从PHP5.5.0开始,此扩展已被弃用,并将在中删除 未来。相反,应该使用or扩展名。 有关更多信息,请参见指南和 信息此功能的替代方案包括:


所有这些代码都不是必需的。我们只需要错误行和前面的几行&中代码行后面的一两行question@DarylGill我知道,但为了安全起见。$result=mysql\u query$con,$sql-in-mysql\u连接排在最后。这是第二个错误的修复程序。添加此$_会话['username']=$_POST['username'];修复第一个问题。@Fred ii-我应该把我的问题重新表述一下,我更感兴趣的是用户能够更改他们的电子邮件和密码。好的。注意:第16行的D:\xampp\htdocs\0100348514\pages\account.php中的未定义索引:username如何?该错误是不言自明的。OP应检查全局$\u会话数组中是否有键为“username”的条目。