Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 602 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

#11
There might be two reasons:

1. Have you opened the connection to the database prior to calling mysql_query function? I don't see that in your code. Use mysql_connect before making the query. See `php.net/manual/en/function.mysql-connect.php`

2. The variable **$username** is used inside a single quote string, so its value will not be evaluated inside the query. The query will definitely fail.

Thirdly, the structure of query is prone to [SQL injection][1]. You may use prepared statements to avoid this security threat.

[1]:

[To see links please register here]

Reply

#12
Try the following code. It may work fine.

$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName ='$username'");

while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
}
Reply

#13
Check your connection first.

Then if you want to fetch the exact value from the database then you should write:

$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName =`$usernam`");

Or you want to fetch the `LIKE` type of value then you should write:

$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '%$username%'");
Reply

#14
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '".$username."'");

while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
}
?>

And if there is a user with a unique user name, you can use "=" for that. There is no need to like.

Your query will be:

mysql_query("SELECT * FROM Users WHERE UserName ='".$username."'");
Reply

#15
As [*scompt.com* explained][1], the query might fail. Use this code the get the error of the query or the correct result:

$username = $_POST['username'];
$password = $_POST['password'];

$result = mysql_query("
SELECT * FROM Users
WHERE UserName LIKE '".mysql_real_escape_string($username)."'
");

if($result)
{
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
}
} else {
echo 'Invalid query: ' . mysql_error() . "\n";
echo 'Whole query: ' . $query;
}

See the [documentation for `mysql_query()`](

[To see links please register here]

) for further information.

The actual error was the single quotes so that the variable `$username` was not parsed. But you should really use `mysql_real_escape_string($username)` to avoid SQL injections.


[1]:

[To see links please register here]

Reply

#16
Try this code it work fine

assign the post variable to the variable

$username = $_POST['uname'];

$password = $_POST['pass'];

$result = mysql_query('SELECT * FROM userData WHERE UserName LIKE $username');

if(!empty($result)){

while($row = mysql_fetch_array($result)){
echo $row['FirstName'];
}
}

Reply

#17
> Make Sure You're Not Closing Database By using db_close() Before To
> Running Your Query:

If you're using multiple queries in a script even you're including other pages which contains queries or database connection, then it might be possible that at any place you use db_close() that would close your database connection so make sure you're not doing this mistake in your scripts.
Reply

#18
$query = "SELECT Name,Mobile,Website,Rating FROM grand_table order by 4";

while( $data = mysql_fetch_array($query))
{
echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td></tr>");
}

Instead of using a WHERE query, you can use this ORDER BY query. It's far better than this for use of a query.

I have done this query and am getting no errors like parameter or boolean.
Reply

#19
If you don't have any MySQL Error appearing while checking, make sure that you properly created your database table. This happened to me. Look for any unwanted commas or quotes.
Reply

#20
This error message is displayed when you have an error in your query which caused it to fail. It will manifest itself when using:

- `mysql_fetch_array`/`mysqli_fetch_array()`
- `mysql_fetch_assoc()`/`mysqli_fetch_assoc()`
- `mysql_num_rows()`/`mysqli_num_rows()`

**Note**: This error does *not* appear if no rows are affected by your query. Only a query with an invalid syntax will generate this error.

**Troubleshooting Steps**

- Make sure you have your development server configured to display all errors. You can do this by placing this at the top of your files or in your config file: [`error_reporting(-1);`](

[To see links please register here]

). If you have any syntax errors this will point them out to you.

- Use [`mysql_error()`](

[To see links please register here]

). `mysql_error()` will report any errors MySQL encountered while performing your query.

Sample usage:

mysql_connect($host, $username, $password) or die("cannot connect");
mysql_select_db($db_name) or die("cannot select DB");

$sql = "SELECT * FROM table_name";
$result = mysql_query($sql);

if (false === $result) {
echo mysql_error();
}



- Run your query from the MySQL command line or a tool like [phpMyAdmin](

[To see links please register here]

). If you have a syntax error in your query this will tell you what it is.

- Make sure your quotes are correct. A missing quote around the query or a value can cause a query to fail.

- Make sure you are escaping your values. Quotes in your query can cause a query to fail (and also leave you open to SQL injections). Use [`mysql_real_escape_string()`][1] to escape your input.

- Make sure you are not mixing `mysqli_*` and `mysql_*` functions. They are not the same thing and cannot be used together. (If you're going to choose one or the other stick with `mysqli_*`. See below for why.)

**Other tips**

`mysql_*` functions should not be used for new code. They are no longer maintained and the community has begun the [deprecation process](

[To see links please register here]

). Instead you should learn about [prepared statements](

[To see links please register here]

) and use either [PDO](

[To see links please register here]

) or [MySQLi](

[To see links please register here]

). If you can't decide, [this article](

[To see links please register here]

) will help to choose. If you care to learn, here is [good PDO tutorial](

[To see links please register here]

).


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through