I'm fairly new to PHP and SQL and as such i'm having an issue with this block of code. What i'm trying to do is have a search function where the user types in a song name which is stored on my server and uses SQL to show the file paths, then once they click the submit button it will populate the web page with the relevant information and play the sound track using the HTML audio function. However, i'm getting error after error with the IF statement :/ Such as : "Parse error: syntax error, unexpected '{' in /home/adixon6/public_html/musicPlayer.php on line 20" i have tried to do the IF statement like i've done my while loop where it uses the : escape to get around using {} for opening and closing and PHP but no dice, still throws errors.
Any ideas on the stupid mistake i'm doing>
Any help would be much appreciated.
<?php
if(isset($_GET['submit'])
{
$search = $_GET['search'];
if(empty($search))
{
echo "Enter a search term";
}
else
{
$sql ="SELECT DISTINCT * FROM tracks WHERE name='$search'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
while($row = mysqli_fetch_array($result)):;?>
<h2><?php echo $row[1]; ?></h2>
<h3><?php echo $row[2]; ?></h3>
<h2><?php echo $row[4]; ?></h2>
<p><?php echo $row[3]; ?><p>
<img src="<?php echo $row[6]; ?>">
<audio controls>
<source src="<?php echo $row[8];?>"
type="audio/mp3">
Your browser doesn't support the audio element.
</audio>
<?php endwhile;
}
}
else
{
$sql ="SELECT TOP 1 * FROM tracks";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
while($row = mysqli_fetch_array($result)):;?>
<h2><?php echo $row[1]; ?></h2>
<h3><?php echo $row[2]; ?></h3>
<h2><?php echo $row[4]; ?></h2>
<p><?php echo $row[3]; ?><p>
<img src="<?php echo $row[6]; ?>">
<audio controls>
<source src="<?php echo $row[8];?>" type="audio/mp3">
Your browser doesn't support the audio element.
</audio>
<?php endwhile;
}
?>
<section class="main-container">
<div class="main-wrapper">
<h2>Music Player</h2>
<form action="" method="GET">
<input name="search" type="text" placeholder="Type here">
<button type="submit" name="submit">Search</button>
</form>
</div>
</section>
<?php
include_once 'footer.php';
?>
Aucun commentaire:
Enregistrer un commentaire