我正在尝试插入我的sql数据库。因为某种原因我得到了 Incorrect integer value: '' for column 'user_id' at row 1
错误。
以下是我的表架构:
如你所见, user_id
是引用另一个表中的列的外键。我不确定你是否需要这些信息,但是是的。我从我的insert php中得到了错误。
以下是我的插入php:
<?php
require_once ('database.php');
if (isset($_POST['send'])) {
$user_id = $_POST['user_id'];
$full_name = $_POST['full_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$fromdate = ($_POST['fromdate']);
$todate = ($_POST['todate']);
$reason = ($_POST['reason']);
$status = ($_POST['status']);
{
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert_query = "INSERT INTO leaves (user_id, full_name, phone, email, fromdate, todate, reason, status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$insert = $database->prepare($insert_query);
$insert->execute(array($user_id, $full_name, $phone, $email, $fromdate, $todate, $reason, $status));
echo "<script>alert('Successfully sent!'); window.location='leaveform.php'</script>";
}
}
?>
形式:
<div class="container">
<div class="card">
<div class="form__name" style="font-family: Questrial; ">
Leave Application Form
</div>
<div class="time__container">
<div class="section">
<div class="box">
1
</div><span>Date</span>
</div>
<form action="insert-leave.php" class="form__time" method="post">
<div class="date">
<label for="date">From</label> <input id="date" type="date" name="fromdate" required>
</div>
<div class="date">
<label for="date">To</label> <input id="date" type="date" name="todate" required>
</div>
<div class="timezone">
<label for="timezone"></label>
</select>
</div>
</div>
<div class="message__container">
<div class="section">
<div class="box">
2
</div><span>Reason</span>
</div>
<textarea cols="50" rows="5" name="reason" required></textarea>
</div>
<div class="contact__container">
<div class="section">
<div class="box">
3
</div><span>Contact Information</span>
</div>
<div class="form__contact">
<div class="cname">
<label for="cname">Name</label> <input name="full_name" type="text" readonly="readonly" value="<?php echo $fullname; ?>" required>
</div>
<div class="cnum">
<label for="cnum">Phone Number</label> <input id="cnum" type="text" readonly="readonly" name="phone" value="<?php echo $contact; ?>" required>
</div>
<div class="email">
<label for="cemail">Email</label> <input id="cemail" name="email" readonly="readonly" value="<?php echo $email; ?>" required>
</div>
<div class="email">
<label for="cemail"></label> <input type="hidden" name="status" required>
</div>
<div class="id">
<label for="id"></label> <input type="hidden" name="user_id" required>
</div>
</div>
</div>
2条答案
按热度按时间ipakzgxi1#
你从来没有给
user_id
```bis0qfac2#
补充