Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Stripe 1
- switch (strtolower($_POST['Stripe1'])) {
- case black:
- $_POST['Stripe1'] = '0';
- break;
- case brown:
- $_POST['Stripe1'] = '1';
- break;
- case red:
- $_POST['Stripe1'] = '2';
- break;
- case orange:
- $_POST['Stripe1'] = '3';
- break;
- case yellow:
- $_POST['Stripe1'] = '4';
- break;
- case green:
- $_POST['Stripe1'] = '5';
- break;
- case blue:
- $_POST['Stripe1'] = '6';
- break;
- case violet:
- $_POST['Stripe1'] = '7';
- break;
- case grey:
- $_POST['Stripe1'] = '8';
- break;
- case white:
- $_POST['Stripe1'] = '9';
- break;
- }
- // Errors
- switch (strtolower($_POST['Stripe1'])) {
- case gold:
- $errors['Stripe1'] = 'The color <b style="color:gold;">gold</b> can not be on stripe 2<br />';
- break;
- case silver:
- $errors['Stripe1'] = 'The color <b style="color:silver;">silver</b> can not be on stripe 2<br />';
- break;
- }
- // Stripe 2
- switch (strtolower($_POST['Stripe2'])) {
- case black:
- $_POST['Stripe2'] = '0';
- break;
- case brown:
- $_POST['Stripe2'] = '1';
- break;
- case red:
- $_POST['Stripe2'] = '2';
- break;
- case orange:
- $_POST['Stripe2'] = '3';
- break;
- case yellow:
- $_POST['Stripe2'] = '4';
- break;
- case green:
- $_POST['Stripe2'] = '5';
- break;
- case blue:
- $_POST['Stripe2'] = '6';
- break;
- case violet:
- $_POST['Stripe2'] = '7';
- break;
- case grey:
- $_POST['Stripe2'] = '8';
- break;
- case white:
- $_POST['Stripe2'] = '9';
- break;
- }
- // Errors
- switch (strtolower($_POST['Stripe2'])) {
- case gold:
- $errors['Stripe2'] = 'The color <b style="color:gold;">gold</b> can not be on stripe 2<br />';
- break;
- case silver:
- $errors['Stripe2'] = 'The color <b style="color:silver;">silver</b> can not be on stripe 2<br />';
- break;
- }
- // Stripe 3
- switch (strtolower($_POST['Stripe3'])) {
- case black:
- $_POST['Stripe3'] = '1';
- break;
- case brown:
- $_POST['Stripe3'] = '10';
- break;
- case red:
- $_POST['Stripe3'] = '100';
- break;
- case orange:
- $_POST['Stripe3'] = '1000';
- break;
- case yellow:
- $_POST['Stripe3'] = '10000';
- break;
- case green:
- $_POST['Stripe3'] = '100000';
- break;
- case blue:
- $_POST['Stripe3'] = '1000000';
- break;
- }
- // Errors
- switch (strtolower($_POST['Stripe3'])) {
- case violet:
- $errors['Stripe3'] = 'The color <b style="color:violet;">violet</b> can not be on stripe 3<br />';
- break;
- case grey:
- $errors['Stripe3'] = 'The color <b style="color:grey;">grey</b> can not be on stripe 3<br />';
- break;
- case white:
- $errors['Stripe3'] = 'The color <b>white</b> can not be on stripe 3<br />';
- break;
- }
- // Stripe 4
- switch (strtolower($_POST['Stripe4'])) {
- case brown:
- $_POST['Stripe4'] = 1;
- break;
- case red:
- $_POST['Stripe4'] = 2;
- break;
- case gold:
- $_POST['Stripe4'] = 5;
- break;
- case silver:
- $_POST['Stripe4'] = 10;
- break;
- }
- // Errors
- switch (strtolower($_POST['Stripe4'])) {
- case orange:
- $errors['Stripe4'] = 'The color <b style="color:orange;">orange</b> can not be on stripe 4<br />';
- break;
- case yellow:
- $errors['Stripe4'] = 'The color <b style="color:yellow;">yellow</b> can not be on stripe 4<br />';
- break;
- case green:
- $errors['Stripe4'] = 'The color <b style="color:green;">green</b> can not be on stripe 4<br />';
- break;
- case blue:
- $errors['Stripe4'] = 'The color <b style="color:blue;">blue</b> can not be on stripe 4<br />';
- break;
- case violet:
- $errors['Stripe4'] = 'The color <b style="color:violet;">violet</b> can not be on stripe 4<br />';
- break;
- case grey:
- $errors['Stripe4'] = 'The color <b style="color:grey;">grey</b> can not be on stripe 4<br />';
- break;
- case white:
- $errors['Stripe4'] = 'The color <b>white</b> can not be on stripe 4<br />';
- break;
- case black:
- $errors['Stripe4'] = 'The color <b style="color:black;">black</b> can not be on stripe 4<br />';
- break;
- }
- $stripe['1'] = $_POST['Stripe1'];
- $stripe['2'] = $_POST['Stripe2'];
- $stripe['3'] = $_POST['Stripe3'];
- $stripe['4'] = $_POST['Stripe4'];
- if(empty($errors)){
- $x = $stripe['1'].$stripe['2'];
- $resistance = $x*$stripe['3'] . "Ω with " . $stripe['4'] . "% in tolerance";
- }else{
- echo '<div id="error">';
- echo $errors['Stripe1'];
- echo $errors['Stripe2'];
- echo $errors['Stripe3'];
- echo $errors['Stripe4'];
- echo '</div>';
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="css/style.css"/>
- <script type="text/javascript" src="js/jquery.mins.js"></script>
- <title>Resistance Calculator</title>
- </head>
- <body>
- <div id="site-wrapper">
- <div id="language">
- <p>Hello World</p>
- </div>
- <h1>Resistor Ω calculator</h1>
- <h2></h2>
- <br /><br /><br />
- <?php
- if ($_GET['id'] == calculated) {
- echo $resistance;
- }
- ?>
- <br />
- <br />
- <div id="calculator" style="color:red;">
- <form method="post" action="?id=calculated">
- <label for="Stripe1" style="color:black;">Stripe 1: </label>
- <input type="text" name="Stripe1" value="" required="required" /> *<br />
- <label for="Stripe1" style="color:black;">Stripe 2: </label>
- <input type="text" name="Stripe2" value="" required="required" /> *<br />
- <label for="Stripe1" style="color:black;">Stripe 3: </label>
- <input type="text" name="Stripe3" value="" required="required" /> *<br />
- <label for="Stripe1" style="color:black;">Stripe 4: </label>
- <input type="text" name="Stripe4" value="" /> *<br />
- <input type="submit" name="submit" value="Calculate" />
- </form>
- <h3>* Required</h3>
- </div>
- <div id="color_table">
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment