0

This is my code:

<?php
include('admin/connect.php');
$applink = $_GET['app'];
$fetchapps = mysql_fetch_array('SELECT * FROM apps WHERE link = "$applink"');
$title = $fetchapps['title'];
?>

And i receive this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in /home/trupu8o/public_html/apps.php on line 4

How i can solve this problem ?

1 Answers1

0

You need to first create a statement, then fetch from that statement:

<?php
include('admin/connect.php');
$applink = $_GET['app'];
$statement = mysql_db_query($database, 'SELECT * FROM apps WHERE link = "'.mysql_real_escape_string($applink).'"');
$fetchapps = mysql_fetch_array($statement);
$title = $fetchapps['title'];
?>

It is assumed that "admin/connect.php" provides the database handle in $database.

Usually you would use that in a loop:

<?php
include('admin/connect.php');
$applink = $_GET['app'];
$statement = mysql_db_query($database, 'SELECT * FROM apps WHERE link = "'.mysql_real_escape_string($applink).'"');
while ($fetchapps = mysql_fetch_array($statement))
{
     $title = $fetchapps['title'];
     // Do something with $title
}
?>
Roland Seuhs
  • 1,708
  • 4
  • 23
  • 47