PHP 无法在满足条件后回显文本

我没有从下面的代码中得到所需的结果。一切正常,但有一个主要问题:

  1. 当数据库中没有歌曲时,它仅通过后退按钮显示空结果。它无法显示回声“抱歉!” 我们的数据库中没有这首歌。

我不知道错误在哪里。所以请帮忙。

提前致谢!!!

<?php


// Php code that fetches audio from the database in server and shows the audio files with singers available for the submitted data


// In submission page DROPDOWN consists of Playlist name and TEXTBOX allows to type the song number for that playlist.


// Standard format for the audio file stored in the databse is Songnumber-Playlistname-Singer's Shortname.mp3


// MP3 files will be inside the AUDIO folder and this PHP code runs from the root folder where there is index.html file for data submission.




// Valid song Numbers of Each Playlists that user choose

$validsongnumbers = [

    'Rock' => 3, 

    'Pop' => 5, 

    'Jazz' => 6

];


// Data captured from dropdown submitted by a user in homepage 

$PlaylistName = $_POST['Dropdown'];

$songNumber = $_POST['songnumber'];


// Check the playlist exists

if (!array_key_exists($PlaylistName, $validsongnumbers)) {

    echo 'Invalid playlist provided.';

    exit;

}


// Check the song number is not greater than what is allowed

if ((int)$songNumber > $validsongnumbers[$PlaylistName]) {

    echo  'Invalid song number provided.';

    exit;

}


慕斯王
浏览 117回答 1
1回答

守着星空守着你

首先,你将“if if”加倍:if&nbsp;if(count($files)&nbsp;<&nbsp;0其次,文件数量永远不能为负。您应该比较 number 是否等于 0(零),而不是小于 0。更新:还是错误的代码:if&nbsp;($count=0)这不是比较,而是赋值。您给出的 $count 值为 0。为了进行比较,您必须使用:if&nbsp;($count&nbsp;==&nbsp;0)
打开App,查看更多内容
随时随地看视频慕课网APP