Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
- echo "Welcome to the member's area, " . $_SESSION['login_user'] . "!";
- } else {
- echo "Please log in first to see this page.";
- header("Location: http://finance.eu.ai");
- }
- //store in db for each user as index,symbol of stocks and quantity,get dynamic price and calculate total
- //Connect to db
- $servername = "sql206.eu.ai";
- $username = "euai_18493372";
- $password = "123456";
- $dbname = "euai_18493372_Users";
- // Create connection
- $conn = new mysqli($servername, $username, $password,$dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- } else {echo "Connected successfully"."<br>";}
- $nameOfUser= $_SESSION['login_user'];
- echo "Name:".$nameOfUser;
- $symbol=$_POST["symbol"];
- echo "Symbol:".$symbol;
- $number=$_POST["number"];
- echo "Num of bought shares:".$number;
- if (!empty($symbol) && !empty($number)) {
- $query = $conn->query("SELECT id FROM users WHERE username='$nameOfUser' ");
- $id=$query; echo "ID found":
- $sql = "INSERT INTO userData (id,symbol,numShares)
- VALUES ( '$id','$symbol','$number')";
- }
- //Why this code wont run after post
- if ($conn->query($sql) === TRUE) {
- echo "New record inserted into database";
- } else {echo "Error in inserting data";
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- echo'<br/>';
- echo '<form action="buy.php" method="post">';
- echo'<input autocomplete="off" autofocus class="form-control" name="symbol" placeholder="Symbol" type="text"/>';
- echo'<br/>';
- echo'<input autocomplete="off" autofocus class="form-control" name="number" placeholder="Shares" type="text"/>';
- echo'<br/>';
- echo'<button class="btn btn-default" type="submit" >Buy</button>';
- echo'</form>';
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement