Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\\xampp\\htdocs\\test\\index.php on line 19
The input to mysql_fetch_Array is a resource, which is also the returned value from mysql_query. If you pass the value $sql to mysql_query(), it will not modify the parameter since it is passed by value. You have to assign the return value to another variable, which will be the desired resource.
$result = mysql_query($sql);
And then, pass the result parameter to mysql_fetch_array :
$row = mysql_fetch_array($result, MYSQL_BOTH)
Another important note: As you might see in all the related threads, read the red box in the php.net for these functions.
Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_query() PDO::query()
Cited from PHP.net about mysql_query()
:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
In your case the resource is returned, but you've forgotten to assign it to anything.
Change mysql_query($sql)
to $resource = mysql_query($sql)
.
Full documentation right here: http://php.net/manual/en/function.mysql-query.php
Change: mysql_query($sql);
To: $sql = mysql_query($sql);
Your parameter to mysql_fetch_array() function is your SQL statement string. This is what your warning say. You should first use $res = mysql_query($sql); and pass $res as parameter to mysql_fetch_array()