doulu8847 2017-02-02 18:10
浏览 36
已采纳

传递变量和PHP

I tried to search through the website but couldn't find a suitable answer for my problem or maybe I'm doing it the wrong way, but I'm making actually a Stock Exchange system for my final year project and I came through this problem. First of all, I'm passing a variable through this:

<a href='#' id='<?php echo "". $row['id'] . ""?>' class="sell">

To the jquery:

$(function(){
  $(".sell").click(function(){
    var element = $(this);
    var userid = element.attr("id");
    var info = 'id=' + userid;

    if (confirm("Do you really want to sell?")){
      $.ajax({
        url: 'sellstock.php',
        type: 'POST',
        data: info,
        success: function(){
          alert('Sold, Please refresh to see your balance');
        }
      });

      $(this).parent().parent().fadeOut(300, function({
        $(this).remove();
      });
    };

    return false;
  });
});

And the jquery calls the sellstock.php

<?php
include('session_user.php');

$stock_id = $_POST['id'];

$sql_getinfo = "SELECT *
                FROM transaction_user
                WHERE id='$stock_id'";

$row_info = mysqli_fetch_array($sql_getinfo, MYSQLI_ASSOC);

$company_id = $row_info['company_id'];
$company_shares = $row_info['number_of_shares_bought'];
$company_price = $row_info['Price'];
$company_total = $row_info['Price_Value'];

$updatedbalance = $balance + $company_total;

$sql_stockinfo = "SELECT Shares_for_sale
                  FROM company_listed
                  WHERE id='$company_id'";

$row_stock = mysqli_fetch_array($sql_stockinfo, MYSQLI_ASSOC);
$shares = $row_stock['Shares_for_sale'];


$updatedshares = $company_shares + $shares;

$updatebalance = "UPDATE balance SET current_balance = '$updatedbalance' where username ='$login_session'";
$resultbalance = mysqli_query($db , $updatebalance);

$updateshare = "UPDATE company_listed SET Shares_for_sale = '$updatedshares' where id= '$stock_id'";
$resultshare = mysqli_query($db, $updateshare);


$sqldelete = "DELETE FROM transaction_user WHERE id='$stock_id'";
$result = mysqli_query($db, $sqldelete);

header("location: Dashboardd.php");
?>

What I want to do is deleting the stock(from the given id), but before that, it should update the balance of the user and update the shares_for_sale of the company.

$sqldelete = "DELETE FROM transaction_user WHERE id='$stock_id'"; $result = mysqli_query($db, $sqldelete);

The $sqldelete line is actually deleting the transaction, but I cant get any updates for the company and user balance. The update queries are working since when I hardcoded them, it was working but the issue is that with the $stock_id, its not working for the $sql_getinfo and since this is not working the $sql_stockinfo will not work and the $updateshare too.

The $login_session and $balance are called from session_user.php and working fine.

tables : https://scontent-mrs1-1.xx.fbcdn.net/v/t35.0-12/16491661_10154975964354500_1753389524_o.jpg?oh=583059fbe0e2b8663acceedf0f1485c6&oe=58964E22

  • 写回答

2条回答 默认 最新

  • douran7929 2017-02-08 18:09
    关注

    Solved

    $sql_getinfo = "SELECT *
                FROM transaction_user
                WHERE id='$stock_id'";
    

    $result = mysqli_query($db, $sql_getinfo); $row_info = mysqli_fetch_array($);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度