PHP form variables, error for mysql_fetch_array()
Grr.. spent the last hour reworking it and it still won't function! I keep getting an error:*Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource*. Any suggestions? Made updates, still getting the same error.
<?
//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 selec开发者_运维知识库t 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>");
}
?>
try
$mySQLselect = "SELECT * FROM tblUsers WHERE userName = '$myUserName'";
On closer inspection
mysql_fetch_array($myRS);
should beL:
mysqli_fetch_array($myRS);
You are missing the last closing curly bracket after:
echo("Thank you for creating an account.");
$mySQLselect = "SELECT * FROM tblUsers WHERE userName = '.$myUserName.'";
There will be dots inserted too, so the query will probably return zero rows. It should be like this:
$mySQLselect = "SELECT * FROM tblUsers WHERE userName = '".$myUserName."'";
精彩评论