Hi I am trying to print all matching rows where the matching Album
or Artist
is matched. I have the code here but something is wrong. I've tried researching it but cant find anything distinct. I think that I am on the right track.
This isn't a duplicate question. Its not the quotes that are the problem because even when I removed them and changed the name it still does not work.
<form>
<h3>Please either search by Artist or Album:</h3>
Artist: <input type="text" name="artist"><br /><br />
Album: <input type="text" name="album"><br /><br />
<input type="submit" value="Search Database" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
$con=mysql_connect('localhost','root','password') or die(mysql_error());
mysql_select_db('music') or die("cannot select DB");
if(!empty($_POST['artist'])) {
$name = $_POST['artist'];
$sql = "SELECT * FROM 'artists' WHERE 'artists name' =".$name;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $row['Album'] . ':' . $row['Artist Name'] . '<br />';
}
} else if(!empty($_POST['album'])) {
$name = $_POST['album'];
$sql = "SELECT * FROM 'albums' WHERE 'Album' =".$name;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $row['Artists'] . ':' . $row['Album'] . '<br />';
}
} else {
echo "<p>Please ente a search query</p>";
}
}
?>
Thanks!