MySQL & PHP Parameter 1 as Resource

MySQL & PHP Parameter 1 as Resource

You need to query the database first.

$queryFP = ("SELECT * FROM db");

Should be:

$queryFP = mysql_query("SELECT * FROM db");

mysql_error() expects parameter 1 to be resource, string given

You are assigning a string to $id within the loop, $id = $rpw['id'];. The next time mysql_fetch_assoc($id) is executed, $id is a string, hence the warning message.

while($rpw = mysql_fetch_assoc($id)) {
echo "Benutzer id: ", $rpw['id'], "\r\n";
}

mysql_query() expects parameter 1 to be string, resource given

Update your code in this way :

$sql = "UPDATE example SET name = $name,email = $email WHERE id = $id";
mysql_query($sql,$con);

mysql_close() expects parameter 1 to be resource, string given

instead of

mysql_close($db_name);

use

mysql_close($con);

Warning: mysql_result() expects parameter 1 to be resource, boolean given

The problem is that mysql_query() is returning a boolean instead of a result resource. There are two reasons this can happen:

  1. You performed query that returns success/fail instead of a result set (e.g. UPDATE)
  2. Your query failed

In your case the query failed. The reason it failed is because you have escaped the back ticks in the PHP string where you did not need to.

Your lines look like this:

$siteTitle = mysql_result(mysql_query("SELECT \`siteTitle\` FROM siteSettings"), 0);

When they should simply be this:

$siteTitle = mysql_result(mysql_query("SELECT `siteTitle` FROM siteSettings"), 0);

Now, some side notes:

  • Don't write new code that uses the mysql_* functions. They are deprecated and will eventually be removed from PHP. Use MySQLi or PDO instead (I personally recommend PDO, YMMV)
  • Nesting database functions in this way is not a particularly good way to write your code. It is much better to check the errors explicitly after every function call.

For example:

$result = mysql_query("SELECT somecol FROM sometable");
if (!$result) {
// Handle error here
}
// Now process the result
  • You should quote either all identifiers, or none, in your queries (preferably all). Quoting only some makes it harder to read.

E.g.

SELECT `siteTitle` FROM `siteSettings`

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...' but my query is correct

$query = "SELECT * FROM newuser WHERE token='$token'";
$result = mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result)) {
do stuff...
}

If the die statement is not executed, $result is OK when you enter the while loop. The problem then is probably that you use $result for a query inside the loop as well, eventually leading to it being set to false.

mysqli_query() expects parameter 1 to be mysqli, resource given in ~\index.php on line 46

You're mixing MySQL API's (mysql_* and mysqli_*)

You have to use something like this:

$con = mysqli_connect("localhost","root","") or die ("could not connect");

And to select your database (mysqli_select_db):

mysqli_select_db("s3f") or die ("no database");   

Also for your connection error handling use (mysqli_connect_error()):

mysqli_connect_error()

Side note:

If you're in a testing environment i would recommend you to put error reporting at the top of your file(s):

<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>

Warning: mysql_error() expects parameter 1 to be resource, string given

There should be session_start() at the top of the page

query need to change as

$query = "SELECT rollno FROM users where username = '".$_SESSION['MM_Username']."' ";

EDIT

Please try something before posting a question here. Please google or go through www.w3school.com for clearing this kind of issues. Make a good knowledge about arrays and mysql connection. And mysql_query function won't work latest PHP version.

Please try following code.

$result = mysql_query($query) or die(mysql_error());
$rows = array();
while($r = mysql_fetch_row($result))
{
$rows[] = $r[0];
}
print_r($rows);

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.



Related Topics



Leave a reply



Submit