mysql_fetch_array():“提供的参数不是有效的MYSQL”,带有单个参数[duplicate]

<?php
   $slug = $_GET['artist'];

//Connection details
$con=mysql_connect("localhost","username","password","mydatabase");
// Check connection
if (!$con) {echo "Failed to connect to MySQL"; exit; };


 $result = mysql_query("SELECT * FROM band WHERE slug ='.$slug.'",$con);

$row = mysql_fetch_array($result);

echo $row[1].'<br>';
echo $row[2].'<br>';
echo $row[3].'<br>';
echo $row[4].'<br>';  
   ?>

I cannot for the life of me figure out why there's a problem with the fetching of the array. Just as a FYI, the $_GET request is to grab the artist variable in the url of another webpage, and then what I wished was to pass that variable through MYSQL as a query, to fetch the record that has the same data held in $artist as it is in the slug attribute of band table.

</div>

Change your SQL Query to

 $result = mysql_query("SELECT * FROM band WHERE slug='$slug'", $con);

no need for .

Also please note that mysql_* functions are deprecated as of PHP 5.5.0 and will be removed in the future. http://php.net/manual/en/function.mysql-query.php

Here I improved your codes for you. try it.

<?php
if(!isset($_GET) or empty($_GET)) {echo 'Get Artist if not found'; }
   $slug = $_GET['artist'];

mysql_connect("localhost","username","password","mydatabase") or die(mysql_error());
$result = mysql_query("SELECT * FROM band WHERE slug ='.$slug.' ");

while($row = mysql_fetch_array($result)) {

echo $row[1].'<br>';
echo $row[2].'<br>';
echo $row[3].'<br>';
echo $row[4].'<br>';  

}
   ?>