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

user2774977
<?php
 session_start();

 $username = "root";
 $password = "password";
 $database = "meipolytechnic";
 mysql_connect('localhost', $username,$password);
 @mysql_select_db($database) or die(mysql_error());


 $username=$_SESSION['MM_Username'];
 $query = "SELECT rollno FROM users where username = '".$username."'";
 $result = mysql_query($query) or die(mysql_error());
 $num = mysql_num_rows($result);

  mysql_close();

   $rows = array();

   while($r = mysql_fetch_row($result))

   {
    $rows[] = $r[0];
   }

   echo ($rows['rollno']);

   ?>

i want to retrieve only the logged in users roll no from users table in database

when i run this code

and log in as foo

i get the following stuff

Unknown column 'foo' in 'where clause'

Shafeeque

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

android sent value to php(mysql_fetch_array() expects parameter 1 to be resource, array given in)

分類Dev

htmlspecialchars() expects parameter 1 to be string, object given for join query

分類Dev

unknow ERROR (in_array() expects parameter 2 to be array, string given)

分類Dev

Error: expects parameter 1 to be mysqli_stmt, boolean given?

分類Dev

mysql_query() expects parameter 2 to be resource, string given in /home/u921305435/public_html/phpinfo.php on line 9

分類Dev

PHP mysqli_query() expects parameter 1 to be mysqli, null given in

分類Dev

mysqli_query() expects parameter 1 to be mysqli, null given :(

分類Dev

mysql_fetch_assoc() expects parameter 1

分類Dev

Error with ConstraintLayout: No resource found that matches the given name

分類Dev

The function expects a tuple set expression for the 1 argument. A string or numeric expression was used

分類Dev

I meet an error with Material-UI and Mobx ,Error: Material-UI: capitalize(string) expects a string argument

分類Dev

"Type error: Argument 1 passed to Model::__construct() must be of the type array, string given, called in TechnicienController.php

分類Dev

XML/Android: No resource found that matches the given name error

分類Dev

Error:(122, 21) No resource found that matches the given name:

分類Dev

WebGL: get error/warning message text as a string

分類Dev

Error:No resource found that matches the given name (at 'resource' with value '@xml/provider_paths')

分類Dev

Getting Error as @Parameter1 is not a parameter for procedure

分類Dev

Failed to claim resource 1 boot error

分類Dev

Passing a parameter to a $resource?

分類Dev

"No resource found that matches the given name"

分類Dev

Mysql error: Warning: #1265 Data truncated for column 'empatt_date' at row 1

分類Dev

Xamarin - Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'

分類Dev

WHERE OR句のmysql_error%s

分類Dev

angular $resource factory pass parameter

分類Dev

未定義の定数mysql_errorの使用-想定される 'mysql_error

分類Dev

How to write a test that expects an error to be issued in java

分類Dev

warning :format 'c' expects argument of type 'int', but argument 2 has type 'char '

分類Dev

警告:mysql_error()は、パラメーター1がリソースであり、文字列が指定されていることを想定しています。

分類Dev

Exception "Procedure or function expects parameter, which was not supplied." thrown even after supplying the parameter

Related 関連記事

  1. 1

    android sent value to php(mysql_fetch_array() expects parameter 1 to be resource, array given in)

  2. 2

    htmlspecialchars() expects parameter 1 to be string, object given for join query

  3. 3

    unknow ERROR (in_array() expects parameter 2 to be array, string given)

  4. 4

    Error: expects parameter 1 to be mysqli_stmt, boolean given?

  5. 5

    mysql_query() expects parameter 2 to be resource, string given in /home/u921305435/public_html/phpinfo.php on line 9

  6. 6

    PHP mysqli_query() expects parameter 1 to be mysqli, null given in

  7. 7

    mysqli_query() expects parameter 1 to be mysqli, null given :(

  8. 8

    mysql_fetch_assoc() expects parameter 1

  9. 9

    Error with ConstraintLayout: No resource found that matches the given name

  10. 10

    The function expects a tuple set expression for the 1 argument. A string or numeric expression was used

  11. 11

    I meet an error with Material-UI and Mobx ,Error: Material-UI: capitalize(string) expects a string argument

  12. 12

    "Type error: Argument 1 passed to Model::__construct() must be of the type array, string given, called in TechnicienController.php

  13. 13

    XML/Android: No resource found that matches the given name error

  14. 14

    Error:(122, 21) No resource found that matches the given name:

  15. 15

    WebGL: get error/warning message text as a string

  16. 16

    Error:No resource found that matches the given name (at 'resource' with value '@xml/provider_paths')

  17. 17

    Getting Error as @Parameter1 is not a parameter for procedure

  18. 18

    Failed to claim resource 1 boot error

  19. 19

    Passing a parameter to a $resource?

  20. 20

    "No resource found that matches the given name"

  21. 21

    Mysql error: Warning: #1265 Data truncated for column 'empatt_date' at row 1

  22. 22

    Xamarin - Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'

  23. 23

    WHERE OR句のmysql_error%s

  24. 24

    angular $resource factory pass parameter

  25. 25

    未定義の定数mysql_errorの使用-想定される 'mysql_error

  26. 26

    How to write a test that expects an error to be issued in java

  27. 27

    warning :format 'c' expects argument of type 'int', but argument 2 has type 'char '

  28. 28

    警告:mysql_error()は、パラメーター1がリソースであり、文字列が指定されていることを想定しています。

  29. 29

    Exception "Procedure or function expects parameter, which was not supplied." thrown even after supplying the parameter

ホットタグ

アーカイブ