L
L
lompas242018-04-19 12:38:13
PHP
lompas24, 2018-04-19 12:38:13

How to make a check?

There is a code for sending data, there is a table with the value id,deposit, how to make it so that when sending the data, it is checked whether this user has this amount on the balance and if it is, it is transferred to the next field

<!doctype html>
<html lang="ru">
<head>

</head>
<body>
<?php
$host="localhost";
$user="admin_1";
$pass="sanua20"; //установленный вами пароль
$db_name="admin_1";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);

//Если переменная Name передана
if (isset($_POST["Name"])) {
    //Вставляем данные, подставляя их в запрос
    $sql = mysql_query("INSERT INTO `vivod` (`Name`, `Price`) 
                        VALUES ('".$_POST['Name']."','".$_POST['Price']."')");
    //Если вставка прошла успешно
    if ($sql) {
        echo "<p>succes</p>";
    } else {
        echo "<p> error</p>";
    }
}
?>
<table>
<form action="" method="post">
    <tr>
        <td>Btc</td>
        <td><input type="text" name="Name"></td>
    </tr>
    <tr>
        <td>Wallet:</td>
        <td><input type="text" name="Price" size="3"> </td>
    </tr>
    <tr>
        <td colspan="2"><input type="submit" value="OK"></td>
    </tr>
</form>
</table>

<?php
//Удаляем, если что
if (isset($_GET['del'])) {
    $sql = mysql_query('DELETE FROM `vivod` WHERE `ID` = "'.$_GET['del'].'"');
    if ($sql) {
        echo "<p>Товар удален.</p>";
    } else {
        echo "<p>Произошла ошибка.</p>";
    }
}

//Получаем данные
$sql = mysql_query('SELECT `ID`, `Name` FROM `vivod`');
while ($result = mysql_fetch_array($sql)) {
    echo $result['ID'].") ".$result['Name']." - <a href='?del=".$result['ID']."'>Удалить</a><br>";
}
?>
</body>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mkmister, 2018-04-28
@mkmister

The answer lies in the question, do you need to deduct funds from the user? So make a query to the database: by user id, get the value of the funds on the user's account, write to a variable, for example $accountFunds , subtract the amount for which the user wants to buy something from the variable, and if the value of the $accountFunds variable >= 0, then feel free to execute a request for debiting funds, otherwise send error. What is not clear here?
PS It's just that you seem to be sitting too long, have a cup of tea and be distracted for 15 minutes, the task is elementary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question