我有兩段代碼,似乎無法迴避哪些問題。 在這個網站搜索,我看到很多其他人有同樣的問題。使用一些給定的答案,我用我給出的代碼構建了代碼,但無濟於事。 ,其中通過所有變量(在一個PHP文件中使用「回聲」)測試我的表單 我的形式如下: 表單數據將不會進入我的數據庫
<div style="position: absolute; left: 10px; top: 290px; z-index: 6;">
<form name="offerings" action="Offer_done.php" method="POST">
<table>
<tr>
<td align="right">First Name:</td>
<td align="left"><input type="text" name="fname" required vspace="4"
/></td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td align="left"><input type="text" name="lname" required vspace="4"
/></td>
</tr>
<tr>
<td align="right">Email:</td>
<td align="left"><input type="text" name="email" required vspace="4"
/></td>
</tr>
<tr>
<td align="right">Choose Your Card:</td>
<td><input list="card_type" name="card_type" required /></td>
<datalist id="card_type">
<option value="American Express">
<option value="Cirrus">
<option value="Diners Club">
<option value="Discover">
<option value="MasterCard">
<option value="Visa">
</datalist>
</tr>
<tr>
<td align="right">Credit Card Num:</td>
<td align="left"><input type="text" name="c_number" required
SIZE="16" MAXLENGTH="16" vspace="4" /></td>
</tr>
<tr>
<td align="right">CV Code:</td>
<td align="left"><input type="text" name="cv_code" required SIZE="4"
MAXLENGTH="4" vspace="4" /></td>
</tr>
<tr>
<td align="right">Offering Amt($):</td>
<td align="left">$<input type="number" name="amount" value="1"
min="0" step="1.00" data-number-to-fixed="2" data-number-
stepfactor="100" class="currency" id="c1" name="money" required
SIZE="7" MAXLENGTH="7" vspace="4" />
</tr>
<tr>
<td align="right"><INPUT TYPE="submit" VALUE="Submit Your Offering">
</td>
<td><input action="action" onclick="window.history.go(-1); return
false;" type="button" value="Cancel - Back To Index Page" /></td>
</tr>
</table>
</form>
</div>
<!- - - - - - - - - - - - - - - - - - End Form- - - - - - - - - - - - - -
- - - - - - - ->
我的PHP文件處理和發送到看起來像這樣:
<?php
$conn = mysqli_connect("localhost", "root", "xuncle", "offerings");
if(!$conn) {
die("connection failed: " .mysqli_connect_error());
}
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$card_type = $_POST['card_type'];
$c_number = $_POST['c_number'];
$cv_code = $_POST['cv_code'];
$amount = $_POST['amount'];
$mysqli_query = "INSERT INTO givers (fname, lname, email, card_type,
c_number, cv_code, amount)
VALUES ($fname, $lname, $email, $card_type, $c_number, $cv_code,
$amount)";
$result = mysqli_query($conn,$sql);
header("Location: index.html");
?>
有人能讓我回到正確的軌道上嗎?
的可能的複製[何時在MySQL中使用單引號,雙引號,反引號和(https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-雙引號和反引號在MySQL) – Qirel
此外:https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef – Qirel
**危險**:您很容易受到[SQL注入攻擊](http://bobby-tables.com/)**,您需要[防禦](http://stackoverflow.com/questions/60174/best -way-to-prevent-sql -injection-in-php)自己從。 – Quentin