Advertisement
cdsatrian

Conditional Input

Sep 25th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Conditional Input</title>
  5.   </head>
  6.   <body>
  7.     <div id='container'>
  8.       <div id='input_box'>
  9.         <form method="POST">
  10.           <table border='1'>
  11.             <tr>
  12.               <td>Ketertarikan</td>
  13.               <td>
  14.                 <input type='radio' name='field' value='sm' checked='checked'/> Sangat Menarik<br/>
  15.                 <input type='radio' name='field' value='me'/> Menarik<br/>
  16.                 <input type='radio' name='field' value='km'/> Kurang Menarik
  17.               </td>
  18.             </tr>
  19.             <tr>
  20.               <td>Berikan nilai untuk Ketertarikan</td>
  21.               <td><input name="nilai" /> Nilai rentang 10-100</td>
  22.             </tr>
  23.             <tr>
  24.               <td colspan="2">
  25.                 <input type="submit" value="kirim" />
  26.               </td>
  27.           </table>
  28.         </form>
  29.       </div>
  30.       <div id='result_box'>
  31. <?php
  32. if(isset($_POST['nilai']))
  33. {
  34.   echo "INSERT INTO table(sm,me,km) VALUES("
  35.        .($_POST['field']=='sm'?$_POST['nilai']:"0").","
  36.        .($_POST['field']=='me'?$_POST['nilai']:"0").","
  37.        .($_POST['field']=='km'?$_POST['nilai']:"0").")";
  38. }
  39. ?>
  40.       </div>
  41.     </div>
  42.   </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement