Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style>
- table {border-collapse: collapse; /* Убираем двойные линии между ячейками */}
- td {
- padding: 3px; /* Поля вокруг содержимого таблицы */
- border: 1px solid black; /* Параметры рамки */
- }
- </style>
- <script type="text/javascript">
- function skidka() {
- var t=document.getElementById('price').value
- var s=document.getElementById('discount').value
- var result=t-(t*s/100);
- document.getElementById('result').innerHTML = 'Цена с учетом скидки='+result.toFixed(2)
- }
- </script>
- <form method="post">
- <p><label>Цена: <input name="price" id="price" type="text"></label></p>
- <p><label>Скидка (%): <input name="discount" id="discount" type="text"></label></p>
- <div id="result"></div>
- <p><input name="calc" type="button" onclick="skidka()" value="Рассчитать"></p>
- <p><input name="send" type="submit" value="Записать в БД"></p>
- </form>
- <?
- $host = 'localhost'; // адрес сервера
- $database = 'dim565_test'; // имя базы данных
- $user = 'dim565_test'; // имя пользователя
- $password = 'dim565_test'; // пароль
- $db = new PDO("mysql:host=$host;dbname=$database", $user, $password);
- if (isset($_POST['send'])) {
- $finalprice=floatval($_POST['price']-($_POST['price']*$_POST['discount']/100));
- $sql_select = "INSERT INTO lessons (price) VALUES(:price)";
- $result = $db->prepare($sql_select);
- $result -> bindParam(':price', $finalprice);
- if ($result -> execute()) echo '<span style="color: green">Новая запись добавлена</span>';
- }
- echo '<h2>Текущие содержимое БД</h2>';
- $sql_select="SELECT id, price from lessons";
- $result = $db->prepare($sql_select);
- $result -> execute();
- echo '<table class="from_db">';
- while($row = $result->fetch()) {
- echo '<tr>';
- echo '<td>'.$row['id'].'</td><td>'.$row['price'].'</td>';
- echo '</tr>';
- }
- echo '</table>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement