mysql_fetch_array() expects parameter 1 to be resource problem
You are not doing error checking after the call to mysql_query:
$result = mysql_query("SELECT * FROM student WHERE IDNO=".$_GET['id']);
if (!$result) { // add this check.
die('Invalid query: ' . mysql_error());
}
In case mysql_query
fails, it returns false
, a boolean
value. When you pass this to mysql_fetch_array
function (which expects a mysql result object
) we get this error.
mysql_fetch_array() expects parameter 1 to be resource
You're not running the query, it's only being stored in a string called $result. Here is the function you need: http://php.net/mysql_query
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in
mysqli_fetch_array()
's 1st parameter must be a result of a query. What you are doing is you are passing the connection (which doesn't make sense) and the query command itself.
Read the doc here: http://php.net/manual/en/mysqli-result.fetch-array.php
To fix this, execute the query first, then store the result to a variable then later fetch that variable.
$sql = "select * from privinsi";
$result = mysqli_query($connection,$sql);
while($r = mysqli_fetch_array($result))
{
// your code here
}
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
A query may fail for various reasons in which case both the mysql_* and the mysqli extension will return false
from their respective query functions/methods. You need to test for that error condition and handle it accordingly.
mysql_ extension:
NOTE The mysql_ functions are deprecated and have been removed in php version 7.
Check $result
before passing it to mysql_fetch_array
. You'll find that it's false
because the query failed. See the [mysql_query
][1] documentation for possible return values and suggestions for how to deal with them.
$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '$username'");
if($result === FALSE) {
trigger_error(mysql_error(), E_USER_ERROR);
}
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
}
Related Topics
PHP Float with 2 Decimal Places: .00
Mysqli Prepare Statement - Returning False, But Why
How to Extract HTML Comments and All HTML Contained by Node
Strange Echo, Print Behaviour in PHP
How to Extend the Zend Navigation Menu View Helper
How to Create Multi-Dimensional Array from a List
How to Check If a User Is Logged-In in PHP
Best Way to Store Ip in Database
Laravel Check If Collection Is Empty
Inspect Xml Created by PHP Soapclient Call Before/Without Sending the Request