我正在開發一個計費系統,現在它非常基本,但我想知道您是否可以幫助我使用我的代碼。如何將HTML表單中的數據插入到MySQL數據庫中?我的代碼:如何將HTML表單插入到MySQL數據庫中?
<?php
if (isset($_POST['submitted'])) {
include('connect-mysql.php');
$date = $_POST['date'];
$charge = $_POST['charge'];
$payment = $_POST['payment'];
$client_no = $_POST['client_no'];
$client_name = $_POST['client_name'];
$check_no = $_POST['check_no'];
$check = $_POST['check'];
$cash = $_POST['cash'];
$notes = $_POST['notes'];
$staff_initials = $_POST['staff_initials'];
$sqlinsert = "INSERT INTO payments (date, charge, payment, client_no, client_name, check_no, check, cash, notes, staff_initials) VALUES ('$date', '$charge', 'payment', '$client_no', '$client_name', '$check_no', '$check', '$cash', '$notes', '$staff_initials')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('There was an error when trying to process your payment. Please contact technical support.');
} //end of nested if statement
} // end of the main if statement
?>
<html>
<head>
<title>New Payment</title>
</head>
<body>
<h1>Please Input Payment Details</h1>
<form action="new_payment.php" method="POST">
<input type="hidden" name="submitted" value="true" />
<fieldset>
<legend>New Payment</legend>
<label>Date:<input type="text" name="date" /></label><br>
<label>Today's Charge: <input type="text" name="charge" /></label><br>
<label>Today's Payment: <input type="text" name="payment" /></label><br>
<label>Client Number: <input type="text" name="client_no" /></label><br>
<label>Client Name: <input type="text" name="client_name" /></label><br>
<label>Check Number: <input type="text" name="check_no" /></label><br>
<label>Check: <input type="text" name="check" /></label><br>
<label>Cash: <input type="text" name="cash" /></label><br>
<label>Notes: <input type="text" name="notes" /></label><br>
<label>Staff Initials: <input type="text" name="staff_initials" /></label><br>
</fieldset>
<br />
<input type="submit" value="Process Payment">
</form>
</body>
</html>
請幫助我,這是非常重要的,我完成這個及時...
你的代碼有什麼問題?它可能行不通,但你並沒有真正解釋清楚問題。 –
使用準備好的查詢來隔離查詢中的數據至關重要。就目前而言,你已經**開放**到SQL注入,如果你還沒有註冊,你將被黑客入侵。 – Brad
你打算使用MySQL還是MySQLi? – balaphp