Advertisement
Guest User

Buy.php

a guest
Jul 16th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1.  
  2. <?php
  3. session_start();
  4. if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
  5.     echo "Welcome to the member's area, " . $_SESSION['login_user'] . "!";
  6. } else {
  7.     echo "Please log in first to see this page.";
  8. header("Location: http://finance.eu.ai");
  9. }
  10.  
  11. //store in db for each user as index,symbol of stocks and quantity,get dynamic price and calculate total
  12. //Connect to db
  13. $servername = "sql206.eu.ai";
  14. $username = "euai_18493372";
  15. $password = "123456";
  16. $dbname = "euai_18493372_Users";
  17. // Create connection
  18. $conn = new mysqli($servername, $username, $password,$dbname);
  19.  
  20. // Check connection
  21. if ($conn->connect_error) {
  22.     die("Connection failed: " . $conn->connect_error);
  23. } else {echo "Connected successfully"."<br>";}
  24.  
  25.  
  26.  
  27. $nameOfUser= $_SESSION['login_user'];
  28. echo "Name:".$nameOfUser;
  29.  
  30. $symbol=$_POST["symbol"];
  31. echo "Symbol:".$symbol;
  32. $number=$_POST["number"];
  33. echo "Num of bought shares:".$number;
  34.  
  35.  
  36. if (!empty($symbol) && !empty($number)) {
  37. $query = $conn->query("SELECT id FROM users WHERE username='$nameOfUser' ");
  38. $id=$query; echo "ID found":
  39. $sql = "INSERT INTO userData  (id,symbol,numShares)
  40. VALUES ( '$id','$symbol','$number')";
  41.  
  42.  
  43. }
  44.  
  45.  
  46. //Why this code wont run after post
  47. if ($conn->query($sql) === TRUE) {
  48.     echo "New record inserted into database";
  49. } else {echo "Error in inserting data";
  50.     echo "Error: " . $sql . "<br>" . $conn->error;
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. echo'<br/>';
  66. echo '<form action="buy.php" method="post">';
  67. echo'<input autocomplete="off" autofocus class="form-control" name="symbol" placeholder="Symbol" type="text"/>';
  68. echo'<br/>';
  69. echo'<input autocomplete="off" autofocus class="form-control" name="number" placeholder="Shares" type="text"/>';
  70. echo'<br/>';
  71. echo'<button class="btn btn-default" type="submit" >Buy</button>';
  72. echo'</form>';
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. $conn->close();
  80.  
  81.  
  82.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement