나는 양식을 가지고 :PDO 삽입 매개 변수 키 대신 매개 변수 값
<form action="includes/Payment.inc.php" method="get" class="px-4 py-4" >
<div class="form-group">
<div class="d-inline py-1"><h5>Payment Type</h5></div>
<select class="bg-white text-dark" name="payment_type">
<option value="Type">Type</option>
<option value="Food">Food</option>
<option value="House-Rent">House-Rent</option>
<option value="Other">Other</option>
</select>
<h5 class="py-1">Amount of Money</h5>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control" name="amount" aria-label="Text input with checkbox">
<span class="input-group-addon">JPY</span>
</div>
<h5 class="py-1">Detail</h5>
<textarea placeholder="Enter The Detail in here" name="detail"></textarea><br>
<label><h5 class="py-1">Date: </h5></label>
<input type="date" name="date"><br>
<button type="submit" name="submit" class="btn btn-primary m-4 border rounded">Submit</button>
</div>
</form>
단순히 PHP 코드를 다음과 같이 데이터베이스에 모든 정보를 넣어 클릭하면 : 나는 양식을 테스트 할 때 다음
<?php
if (isset($_GET['submit'])) {
include_once 'dbh.inc.php';
$payment_type = $_GET['payment'];
$amount_money = filter_input(INPUT_GET,'amount',FILTER_SANITIZE_NUMBER_INT);
$detail = filter_input(INPUT_GET,'detail',FILTER_SANITIZE_STRING);
$date = $_GET['date'];
if (empty($amount_money)) {
header('Location: ../Data.php?money_empty');
exit();
}
else {
$sql = "INSERT INTO payment(payment_type,amount,detail,payment_date)
VALUES (':payment_type',':amount',':detail',':payment_date')";
$result = $conn->prepare($sql);
$result->bindParam(':payment_type',$payment_type,PDO::PARAM_STR);
$result->bindParam(':amount',$amount_money,PDO::PARAM_INT);
$result->bindParam(':detail',$detail,PDO::PARAM_STR);
$result->bindParam(':payment_date',$date,PDO::PARAM_STR);
$result->execute();
header("Location: ../Data.php?payment_success");
exit();
}
}
실행이 완료되었지만 "지불"테이블을 확인할 때 여기에 내가 가지고있는 것이 있습니다 :
- payment_type (varchar) = ": paym 세부 사항 "
- PAYMENT_DATE (일) ="0000-00-00 ":"
- 양 (INT) = 0
- 상세 (VARCHAR)를 = "ent_type. 내 코드에 어떤 문제가 있습니까?
"서버와의 연결이 끊어졌습니다"와 무슨 관련이 있습니까? 제목과 질문이 일치하지 않는 것 같습니다. –
죄송합니다. 제 이전 질문의 제목이었습니다. 편집 해주세요. –
고맙습니다. 문서 및 명확한 대답을 주셔서 감사합니다 –