PHP表单变量,mysql_fetch_array()的错误

时间:2011-06-08 23:44:00

标签: php database arrays variables

Grr ..花了最后一小时重新加工它仍然无法正常工作!我一直收到错误:*警告:mysql_fetch_array():提供的参数不是有效的MySQL结果资源*。有什么建议?做了更新,仍然得到同样的错误。

<?    
    //Extract data from form
    if(isset($_POST["editUserName"])){
 $myUserName = mysqli_real_escape_string($myConn, $_POST["editUserName"]);
    }

 if(isset($_POST["updateSubmit"])){ 
  $mySubmit = mysqli_real_escape_string($myConn, $_POST["updateSubmit"]);
    }


    //Verify form was submitted before beginning database interaction
    if(isset($_POST["updateSubmit"]))
    {

    //Create an SQL delete statement to select the desired record
    $mySQLselect = "SELECT * FROM tblUsers WHERE userName = '$myUserName'";
    $myRS = mysqli_query($myConn, $mySQLselect) or die('Error: ' .mysqli_error($myConn));
    $myData = mysql_fetch_array($myRS);

    //Create form output for editing
    echo("<form name='frmEdit' id='frmEdit' action='doEdit.php' method='post'>");
    echo("<input type='hidden' name='hidUserName' id='hidUserName' value='$myUserName'/>");     
    echo("<p>User Name: <input type='text' name='BuserName' id='BuserName' value='$myData[userName]'/></p>");
    echo("<p>Password: <input type='text' name='BuserPass' id='BuserPass' value='$myData[userPass]'/></p>");
    echo("<p>First Name: <input type='text' name='BfirstName' id='BfirstName' value='$myData[userFirst]'/></p>");
    echo("<p>Last Name: <input type='text' name='BlastName' id='BlastName' value='$myData[userLast]'/></p>");
    echo("<p>Address: <input type='text' name='Baddress' id='Baddress' value='$myData[address]'/></p>");
    echo("<p>City: <input type='text' name='Bcity' id='Bcity'value='$myData[city]'/></p>");
    echo("<p>State: <input type='text' name='Bstate' id='Bstate' value='$myData[state]'/></p>");
    echo("<p>Zip: <input type='text' name='Bzip' id='Bzip' value='$myData[zip]'/></p>");
    echo("<p>Email: <input type='text' name='Bemail' id='Bemail'$myData[email]'/></p>");
    echo("<p>Phone: <input type='text' name='Bphone' id='Bphone'$myData[phone]'/></p>");
    echo("<p><input type='submit' name='btnDoEdit' id='btnDoEdit' value='Make Changes'/></p>");
    echo("</form>");
            }   

            ?>

2 个答案:

答案 0 :(得分:4)

$mySQLselect = "SELECT * FROM tblUsers WHERE userName = '$myUserName'";

仔细检查

mysql_fetch_array($myRS);

应该是L:

mysqli_fetch_array($myRS);

您错过了最后一个结束花括号:

echo("Thank you for creating an account.");

答案 1 :(得分:0)

$mySQLselect = "SELECT * FROM tblUsers WHERE userName = '.$myUserName.'";

也会插入点,因此查询可能会返回零行。它应该是这样的:

$mySQLselect = "SELECT * FROM tblUsers WHERE userName = '".$myUserName."'";