Hier ist der einfache Code:html5 Anzahl Eingangstyp Stufe Attribut Multiplizieren Zahl mit 100
Amount: <input type='number' step="0.01" min="1" max="500" name='pr_amount' id='pr_amount' /><br>
dieses Formular mit PHP gemacht wird, um Daten in MYSQL Datenbank einzufügen. INPUT 1.50 OUTPUT in der Datenbank 150,00
Wie dieses Problem zu lösen? Muss ich den PHP-Code $ pr_amount/100 verwenden oder gibt es einen anderen Weg? Ohne Schritt = "0.01" wird nicht die Dezimalstelle in Punkten oder der Cent-Wert von Dollar verwendet.
PHP-Teil: payment.inc.php
if (isset($_POST['pr_amount'], $_POST['pr_processor'],$_POST['pr_comment'])) {
// Sanitize and validate the data passed in
$pr_amount = filter_input(INPUT_POST, 'pr_amount', FILTER_SANITIZE_NUMBER_FLOAT);
$pr_processor = filter_input(INPUT_POST, 'pr_processor', FILTER_SANITIZE_STRING);
$pr_comment = filter_input(INPUT_POST, 'pr_comment', FILTER_SANITIZE_STRING);
$user_id = htmlentities($_SESSION['user_id']);
// for checking minimum payout allowed
if ($pr_amount < 1) {
// If it's not, something really odd has happened
$error_msg_payout .= '<p class="error">Minimum Payout is $1.00, for INR withdraw Minimum payout is Rs.100</p>';
}
if(empty($pr_amount || $pr_comment)) {
$error_msg_payout .= '<p class="error">User must input all field</p>';
}
// checking if pr amount is above the available balance
$stmt_balance = $mysqli->prepare("SELECT current_balance FROM client WHERE user_id = ?");
$stmt_balance->bind_param('i', $user_id);
$stmt_balance->execute();
$stmt_balance->store_result();
if($stmt_balance < $pr_amount){
// If it's not, something really odd has happened
$error_msg_payout .= '<p class="error">Payment request amount is greater than the available balance.</p>';
}
$stmt_balance->close();
//-------For checking pr comment validity
if (strlen($pr_comment) > 150) {
// If it's not, something really odd has happened
$error_msg_payout .= '<p class="error">Payment instruction should be within 150 charecters</p>';
}
if (!ctype_alpha(str_replace(' ', '',$pr_comment))) {
$error_msg_payout .= '<p class="error">Payment Instruction Include disallowed charecters</p>';
}
if (empty($error_msg_payout)) {
// Insert the new account into the database
if ($insert_stmt_payout = $mysqli->prepare("INSERT INTO payment (user_id,pr_amount,pr_comment,pr_processor)
SELECT ?, ?, ?, pr_processor FROM paymentlist WHERE pr_processor = ?")) {
$insert_stmt_payout->bind_param('idss', $user_id,$pr_amount,$pr_comment,$pr_processor);
// Execute the prepared query.
if (! $insert_stmt_payout->execute()) {
header('Location: ../error.php?err=AddPayment failure: INSERT');
exit();
}
}
//---deducting balance after succesful request
$stmt_deduct = $mysqli->prepare("UPDATE client SET current_balance = (current_balance-?) WHERE user_id = ?");
$stmt_deduct->bind_param('di', $pr_amount,$user_id);
$stmt_deduct->execute();
if (! $stmt_deduct->execute()) {
header('Location: ../error.php?err=AddPayment failure: INSERT AMOUNT');
exit();
}
$stmt_deduct->close();
header('Location: ./payment.php');
exit();
}
}
HTML TEIL: payment.php
<form method="post" name="payment_request" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>">
Add Request:
<?php
$stmt = $mysqli->prepare('SELECT pr_processor FROM paymentlist ');
$stmt->execute(); // Execute the prepared query.
$stmt->bind_result($pr_processor);
$stmt->store_result();
echo "<select name='pr_processor'>";
while($stmt->fetch()) {
echo "<option value='" . $pr_processor . "'>" . $pr_processor . "</option>";
}
$stmt->close();
echo "</select>";
?> <br>
Amount: <input type='number' min="1" max="500" name='pr_amount' id='pr_amount' step='0.01' value='0.00' placeholder='0.00' /><br>
Payment Instruction: <input type='text' name='pr_comment' id='pr_comment' /><br>
<input type="submit" value="Add Payout Request" name="addpayment" />
</form>
Hinweis: Wenn ich nicht tun benutze schritt, dann braucht es nur ganzzahl und ausgabe der eingabe ist vollkommen in ordnung. Aber ich brauchte die Eingabe in Geldwert mit Dezimalpunkt.
Ich habe den PHP-Teil mit vollem Code aktualisiert, ja ich verarbeite den $ pr_amount, bevor ich ihn zur Datenbank hinzufüge. Bitte schau es dir an. Danke – mimi
Sie müssen das Flag FILTER_FLAG_ALLOW_FRACTION zu Ihrem Filter-Eingangsfunktionsaufruf hinzufügen. Ihr Filter sollte also lauten: '$ pr_amount = filter_input (INPUT_POST, 'pr_amount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);'. Siehe diesen Link: https://www.w3schools.com/php/filter_sanitize_number_float.asp –
das hat einfach perfekt funktioniert, du hast mir gute Dinge beigebracht! – mimi