I have two tables wallet
(table 1) and api
(table 2).
Right now I have made the part where I insert the submitted data to my wallet
table. This is the code for this specifically:
<?php
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$coin = mysqli_real_escape_string($conn, $_REQUEST['coin']);
$user_coins = mysqli_real_escape_string($conn, $_REQUEST['coins_quantity']);
$sql = "INSERT INTO wallet (coin, user_coins) VALUES ('$coin', '$user_coins')";
if ($conn->query($sql)){
echo "Added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
}
?>
Where this is my form the code above:
<form method="post">
<div class="form-group row justify-content-center">
<label class="col-sm-3 col-form-label">Coin</label>
<div class="col-sm-6">
<select class="form-control" name="coin">
<?php
$sql = "SELECT name, symbol FROM api";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
unset($symbol, $name);
$symbol = $row['symbol'];
$name = $row['name'];
echo '<option value="'.$symbol.'">'.$name.'</option>';
}
?>
</select>
</div>
</div>
<div class="form-group row justify-content-center">
<label class="col-sm-3 col-form-label">Coins</label>
<div class="col-sm-6">
<input type="number" class="form-control" name="coins_quantity" placeholder="5">
</div>
</div>
<div class="form-group row justify-content-center text-center">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</div>
</form>
In my table wallet
(table 1) I have created columns which are coin
, user_coins
and coin_price
.
While in table api
(table 2) I have name
, price
, symbol
and more.
I want to insert data to coin_price
in wallet
from the price
column in the api
table, and I want the price
from the selected '<option value="'.$symbol.'">'.$name.'</option>';
.
How can I do this?