Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. $sql_host = "localhost";
  4. $sql_user = "root";
  5. $sql_pass = "root";
  6. $db_name = "items";
  7.  
  8. $data_sql = mysql_connect($sql_host, $sql_user, $sql_pass);
  9. if (!$data_sql) die("Can't connect to MySql");
  10. mysql_select_db($db_name,$data_sql) or die("Can't select database");
  11.  
  12. $pricz = mysql_query("SELECT * FROM items WHERE username='admin'");
  13. $unsold = mysql_fetch_assoc($pricz);
  14.  
  15. echo ' <p>The current price is: <strong style="color:orange">';
  16.  
  17. if($unsold['unsold'] != ''){
  18. echo $unsold['unsold'];
  19. }else {
  20. echo '<b>You havent added a price yet.';
  21. }
  22.  
  23. echo '
  24. <center><form action="" method="post" >
  25. <input type="text" name="price" placeholder="Enter new Price"/>
  26. <input class="button" type="submit" name="submitprc" value="Save"></form>';
  27.  
  28. if(isset($_POST['submitprc'])){
  29. $price = $_POST['price'];
  30. mysql_query("update items set unsold=(unsold + '$price') where username='admin'");
  31. }
  32.  
  33. /*
  34.  
  35. --
  36. -- Table structure for table `items`
  37. --
  38.  
  39. CREATE TABLE `items` (
  40. `id` int(6) NOT NULL,
  41. `username` varchar(30) NOT NULL,
  42. `unsold` decimal(10,2) NOT NULL,
  43. `sold` decimal(10,2) NOT NULL,
  44. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
  45.  
  46. --
  47. -- Dumping data for table `items`
  48. --
  49.  
  50. INSERT INTO `items` (`id`, `username`, `unsold`, `sold`) VALUES
  51. (1, 'admin', '0.00', '0.50');
  52. */
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement