我想表單數據到表寄宿插入到mysql數據庫的寄宿家庭。我查了很多次,但沒有錯誤。我不知道是否我的插入查詢錯誤?插入我的寄宿表中沒有錯誤,沒有工作
傢伙在這裏是PHP代碼中插入表格值到寄宿表
<?php
include("connection.php");
$sessid = $_SESSION["sess_id"];
$resultowner = mysqli_query($conn, "select * from owner where owner_id =$sessid");
$rowowner = mysqli_fetch_assoc($resultowner);
if(isset($_POST["addbtn"]))
{
$name = $_POST["name"];
$postcode = $_POST["postcode"];
$city = $_POST["city"];
$state = $_POST["state"];
$address = $_POST["address"];
$capacity = $_POST["capacity"];
$room = $_POST["room"];
$bathroom = $_POST["bathroom"];
$amenity = $_POST["amenity"];
$status= $_POST["status"];
$price= $_POST["price"];
$category = $_POST["category"];
$sessid = $_SESSION["sess_id"];
$result = mysqli_query($conn,"insert into homestay(homestay_name,homestay_postcode,homestay_city,homestay_state,homestay_address,homestay_capacity,homestay_rooms,homestay_bathrooms,homestay_amenities,homestay_blacklist_status,homestay_price_perday,category_id,owner_id)values('$name',$postcode,'$city','$state','$address',$capacity,$room,$bathroom,'$amenity','$status',$price,$category,$sessid)");
if($result)
echo "<script type='text/javascript'>alert('$name');</script>";
}
?>
的connection.php鏈接到寄宿數據庫
<?php
$conn = mysqli_connect("localhost","root","","homestay");
session_start();
?>
這是形式的詳情
<form id="form_register" name="homestay_form" method="post">
<fieldset>
<legend>Edit Homestays</legend>
<label for="name">Homestay Name</label>
<input type="text" name="name" id="name" maxlength="15"/>
<label for="room">Homestay Rooms</label>
<input type="text" name="room" id="room" maxlength="2"/>
<label for="room">Homestay Bathrooms</label>
<input type="text" name="bathroom" id="bathroom" maxlength="2"/>
<label for="capacity">Homestay Capacity</label>
<input type="text" name="capacity" id="capacity" maxlength="2" />
<label for="address">Homestay Address</label>
<textarea name="address" style="text-align:left;" maxlength="50" rows="5" cols="40"></textarea>
<label for="postcode">Homestay Postcode</label>
<input type="text" name="postcode" id="postcode" maxlength="5"/>
<label for="state">Homestay City</label>
<input type="text" name="city" id="state" maxlength="15"/>
<label for="reg_city">Homestay State</label>
<select name="state" style="width:300px;">
<option value="Johor">Johor</option>
<option value="Kedah">Kedah </option>
<option value="Kelantan">Kelantan</option>
<option value="Kuala Lumpur">Kuala Lumpur</option>
<option value="Melaka">Melaka</option>
<option value="Negeri Sembilan">Negeri Sembilan</option>
<option value="Pahang">Pahang</option>
<option value="Perak">Perak</option>
<option value="Perlis">Perlis </option>
<option value="Pulau Pinang">Pulau Pinang </option>
<option value="Sabah">Sabah</option>
<option value="Sarawak">Sarawak</option>
<option value="Selangor">Selangor</option>
<option value="Terengganu">Terengganu</option>
</select>
<label for="amenity">Homestay Amenities</label>
<input type="text" name="amenity" id="amenity" maxlength="100"/>
<label for="price">Homestay Price Per Day</label>
<input type="text" name="price" id="price" maxlength="4"/>
`
<label for="category">Homestay Category</label>
<select name="category">
<?php
$result2 = mysqli_query($conn,"select * from category");
while($row2 = mysqli_fetch_assoc($result2)){?>
<option value="<?php echo $row2['category_id']; ?>" > <?php echo $row2['category_types'] ;?>
</option>
<?php}?>
</select>
<label for="status">Homestay Blacklist Status</label>
<select name="status" style="width:300px;">
<option value="Available">Available</option>
<option value="Non-available">Non-available</option>
</select>
<label for="reg_profile">Profile Picture*</label>
<input type="file" name="profile_pic" id="reg_picture"/>
<input type="submit" name="addbtn" value="Add" id="reg_submit" />
</fieldset>
</form>
這裏是寄宿表
homestay_id int(10)
homestay_name varchar(50)
homestay_address varchar(50)
homestay_postcode int(5) unsigned zerofill
homestay_state varchar(20)
homestay_city varchar(20)
homestay_capacity int(5)
homestay_rooms int(3)
homestay_bathrooms int(3)
homestay_amenities varchar(50)
homestay_blacklist_status varchar(50)
homestay_price_perday double
category_id int(11)
owner_id int(11)
這裏是錯誤>>複製項目「1-4」關鍵「category_id_3」 –