search and display value from database using prompt box in php -


hai want ask how search , display value database using prompt box in php.what meant have button when user click button prompt box appear , ask phone number.when user type phone number , click ok, search phone number display table user can print..i not know how it..hope can give full example me...

here code prompt box..

<html> <head> </head> <body> <form name=myform> <input type=button value="try now"  onclick=" s=prompt('enter phone number','phone'); alert('hello '+s+'!')"> </form> </body> </html> 

the answer question use ajax.

once have gathered phone number user, need make ajax request php file on server pass php file phone number have collected, , php file returns whatever information want display in whatever format choose have return. part, of these decisions entirely you.

some recommendations:

  • use jquery. make javascript processing easier including dom processing , ajax requests.
  • if php server has json, use return format, unless more convenient return raw html string can print.

you have not been clear value being returned database, example cannot exact. however, if using jquery, following might you.

your html file

<html>     <head>         <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>         <script type="text/javascript">         $( document ).ready(             function(){                 $( '#mybutton' ).click(                     function( e ) {                         e.preventdefault();                          var phone = prompt( 'enter phone number', '555-555-5555' );                         $.post(                             'your_file.php',                             {                                 phone: phone                             },                             function( data, textstatus, jqxhr ) {                                 // instead of alerting this, should print it,                                 // parse it, or whatever else.                                 alert( data );                             },                             'html'                     }                 );             }         );         </script>     </head>     <body>         <form>             <input type="button" id="mybutton" value="try now" />         </form>     </body> </html> 

your php file (your_file.php above javascript)

<?php  if ( isset( $_post[ 'phone' ] ) ) {     // database processing here, using phone number passed     // in javascript. stored in $_post[ 'phone' ].      // then, die() whatever html or json or whatever information     // returning.     die( 'some html print' ); } else {     // error: no phone number posted.     die( '-1' ); }  ?> 

Comments