0

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 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>");
            }   

            ?>
1
  • 5
    Please don't edit the question to make the existing answers meaningless. If you have a new problem post a new question. Reference this one (in it's original form) and explain that it's a new issue. Commented Jun 9, 2011 at 10:05

2 Answers 2

4

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.");
7
  • Tried that, and while it may be part of the problem, the only error it is coming up with is for the mysql_fetch_array(). Commented Jun 8, 2011 at 23:56
  • 1
    @Jason McCreary ... thx but missed one thing :) .... @Anna ... look at the updated answer Commented Jun 9, 2011 at 0:00
  • Rock on! Getting closer! Who knew an 'i' could cause so much trouble! Commented Jun 9, 2011 at 0:12
  • That in particular error.. working on the next.. I'll update the code above. Commented Jun 9, 2011 at 0:21
  • 1
    @Anna i have updated the answer above. However you should create new questions for new errors :) Commented Jun 9, 2011 at 0:29
0
$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."'";
6
  • Tried that, and while it may be part of the problem, the only error it is coming up with is for the mysql_fetch_array(). Commented Jun 8, 2011 at 23:55
  • Yes, that goes together, if the query returns no rows, mysql_Fetch_array() throws this error. After you change this, you still get the error?If yes, I would check if the query really fits to the structure of the table. Commented Jun 8, 2011 at 23:57
  • I'm guessing this would be easier if I had access to the database? I don't unfortunately, the joys of homework. Commented Jun 9, 2011 at 0:00
  • Well, yes, that would be very helpful. I dont't know, if your current access level will allow you this, but you can do two things: 1. Select structure from catalogs (information_schema table) 2. Install your own phpMyAdmin Commented Jun 9, 2011 at 0:02
  • That's incorrect—at least with mysqli_fetch_array(), it returns null if the query results in 0 rows. It only errors if it's passed an invalid MySQLi_Result. The likely problem here is that mysql_fetch_array() (rather than mysqli_*) is being used with a MySQLi_Result. Commented Jun 9, 2011 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.