简体   繁体   English

插入更新不会在表和数据库中更新

[英]Insert update won't update in table and in database

Having trouble update in PHP the code is running no errors but when I enter a amount, it doesn't update in my tables and in my database please help. 在PHP中更新时遇到麻烦,代码没有运行错误,但是当我输入金额时,它在表和数据库中都不会更新,请提供帮助。 By the way I took some codes in my previous program so maybe some variable codes are no appropriate in the process. 顺便说一下,我在以前的程序中使用了一些代码,因此在此过程中可能不适合使用某些可变代码。 Thank you. 谢谢。

Here's the code: 这是代码:

load.php load.php

<form method="POST" action="process-load.php">
<?php
require_once('connect/connect.php');
$id = mysql_escape_string($_GET['id']);
$sql = 'SELECT * FROM cards WHERE id='.$id.' LIMIT 0, 1';
$qry = mysql_query($sql);
$data = mysql_fetch_array($qry);
$html = '';

    $html .= '<div class="box">';
$html .= '<b> Card #: '.$data['cardno'].'</b><br />';
$html .= '<b>Current Balance: </b>'.$data['balance'].'<br />';
$html .= '<b>Enter Addition Load: </b><input type="text" name="load" size="5" /><br />';
$html .= '<input type="hidden" value="'.$_GET['id'].'" name="id" />';
$html .= '<input type="hidden" value="'.$data['balance'].'" name="bal" />';
$html .= '<input type="submit" value="Submit" name="submit" />';
$html .= '</div>';

echo $html;
?>
</form>

process-load.php process-load.php

<?php
session_start(); //don't forget to start session or else session will not be red

if(isset($_POST['submit'])) {       
    require_once('connect/connect.php');

    $id = mysql_escape_string($_POST['id']);
    $bal = $_POST['bal'];
    $load = $_POST['load'];
    $select_sql = 'SELECT balance FROM cards WHERE id="'.$id.'" LIMIT 0, 1';
    $qry = mysql_query($select_sql);
    $data = mysql_fetch_array($qry);            
    $new_bal = $data['balance'] + $bal; 
    $sql_update = 'UPDATE cards SET balance="'.mysql_escape_string($new_bal).'" WHERE id="'.$id.'"';
    $qry2 = mysql_query($sql_update);
    $bill = $bal += $load;

    $_SESSION['profit'] += $bill; //add total bill always to your session

    if($qry2) { 
        ?>
        <script>            
            alert('Thank you.\n New Balance: <?php echo $bill; ?>');
            window.location.href = 'index.php?page=show';
        </script>
        <?php
    } else {
        ?>
        <script>
            alert('Failed to load card.';);
            window.location.href = 'index.php?page=show';
        </script>
        <?php
    }
    mysql_close($con);
}
?>

you need to echo out this thing 你需要回声这件事

echo $sql_update = 'UPDATE cards SET balance="'.mysql_escape_string($new_bal).'" WHERE id="'.$id.'"'; echo $sql_update = 'UPDATE cards SET balance="'.mysql_escape_string($new_bal).'" WHERE id="'.$id.'"';

check what you are getting here. 检查你在这里得到什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM