mysql - what if condition to put in php code -


I have created a sound dictionary, the user uses a word and the meaning related to my SQL database is brought, this screen And then changes into speech.It's all working fine.

I just want to add a condition: if the user enters the word that is not present in my database, then it outputs the "Sorry word not found" message, and nothing in the audio Should not be played at present if I am entering a word which is not present, then I am getting the audio of 'undefined index .. some ..'

Please tell me where the condition and What to add is to add A. Here is my code

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Word meaning & lt; / Title & gt; & Lt ;? Php mysql_connect ("localhost", "root", "abcd"); Mysql_select_db ("dictionary"); If (isset ($ _ POST ['deposit1'])) {$ req = $ _ request ['word']; $ StrSQL = "SELECT * FROM dict WHERE word = '$ req'"; $ Rs = mysql_query ($ strSQL); While ($ line = mysql_fetch_array ($ rs)) {$ x = $ line ["word"]; $ Y = $ line ["meaning"]; $ Z = $ line ["options"]; Echo "& lt; b & gt; Word & lt; / b & gt;:" $ X. "
" ; Echo "& lt; b & gt; अर्थ & lt; / b & gt ;:" $ Y. "
" ; Echo "& lt; b & gt; synonyms & lt; / b & gt;:" $ Z. "
" ; }} Mysql_close (); ? & Gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form name = "form1" action = "lastry.php" method = "post" & gt; & Lt; Input type = "text" name = "word" value = "& lt ;? php echo isset ($ _ POST ['word'])? $ _ POST ['word']: ''? & Gt;" X-webkit-speech / & gt; & Lt; Input type = "submit" name = "plus1" value = "submit" & gt; & Lt; / Form & gt; & Lt ;? Php if ($ _ POST) {? & Gt; & Lt; P & gt; Hear word & lt; Audio control = "control" & gt; & Lt; source src = "http://speechutil.com/convert/ogg?text='<?php echo urlencode ($ x);? & gt; '' & type =" audio / mp3 "/ & gt; & lt; / audio & gt; / l & gt; & lt; br & gt; & lt; br & gt; Meaning & lt; audio control = "control" & gt; & lt; source src = "http://speechutil.com/convert/ogg?text='<?php echo urlencode ($ y) ;? & Gt; "& Amp; Type =" audio / mp3 "/> gt; & gt; & gt; & lt; / p & gt; & lt; br & gt; & lt; br & gt; Lt; p & gt; Listen to synonyms & lt; audio control = "control" & gt; source src = "http://speechutil.com/convert/ogg?text='<?php echo urlencode ($ z) ;? & Gt; '' & amp; Type = "Audio / MP3" /> & Lt; / Audio & gt; & Lt; / P & gt; & Lt ;? Php}? & Gt; & Lt; / Body & gt; & Lt; / Html & gt; $ rs = mysql_query ($ strSQL)

instant $ rs = Mysql_query ($ strSQL); , line $ num_rows = mysql_num_rows ($ rs); , you can do the following:

  If ($ num_rows> 0) loop, which you already have I / o else {echo 'Sorry word not found '; }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -