我已經創建了一個表單,但是php post頁面沒有發佈表單到數據庫。PHP表單不提交到數據庫
我不知道什麼是錯的代碼..
<?php
// Create connection
$conn = mysqli_connect("localhost", "username", "password", "database");
if(isset($_POST['submit']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
move_uploaded_file($file_loc,$folder.$file);
mysqli_query($conn,"INSERT INTO claim_info (
claimant_name,
claimant_surname,
file,
size,
type,
claimant_title,
claimant_position,
claimant_dob,
claimant_ni
) VALUES (
'$_POST[claimant_name]',
'$_POST[claimant_surname]',
'$file',
'$file_size',
'$file_type',
'$_POST[claimant_title]',
'$_POST[claimant_position]',
'$_POST[claimant_dob]')");
if (mysqli_query) {
echo "success!";
}
mysqli_close($conn);
}
?>
創建的形式是如下:
<head>
<meta charset="UTF-8">
<title>Claim Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<title>Accident Claim - Form</title>
<style>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form method="post" action="test.php" enctype="multipart/form-data">
<div id="stage1" class="form-group">
<h1>Claiment Detials</h1>
<label for="claimant_title">Title:</label>
<select class="form-control" id="claimant_title" name="claimant_title">
<option value=""></option>
<option value="Mr">Mr</option>
<option value="Ms">Ms</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
</select><br />
<label for="claimant_position">Position: </label>
<select class="form-control" id="claimant_position" name="claimant_position">
<option value=""></option>
<option value="Driver">Driver</option>
<option value="Passenger">Passenger</option>
</select><br />
<label for="claimant_name">Name:</label>
<input class="form-control" id="claimant_name" name="claimant_name" /><br />
<label for="claimant_surname">Surname:</label>
<input class="form-control" id="claimant_surname" name="claimant_surname" /><br />
<label for="claimant_dob">DOB:</label>
<input class="form-control" id="claimant_dob" name="claimant_dob" placeholder="DD/MM/YYYY" /><br />
<label for="claimant_ni">N.I.:</label>
<input class="form-control" id="claimant_ni" name="claimant_ni" /><br />
<label for="claimant_address">Address:</label>
<input class="form-control" id="claimant_address" name="claimant_address" /><br />
<label for="claimant_postcode">Post Code:</label> <input class="form-control" id="claimant_postcode" name="claimant_postcode" /><br />
<label for="phone">Phone:</label>
<input class="form-control" id="claimant_phone" name="pclaimant_hone" /><br />
<label for="email">Email:</label>
<input class="form-control" id="claimant_email" name="claimant_email" /><br />
<label for="file">File:</label>
<input class="form-control" id="file" name="file" type="file"><br />
<span id="error-message1"></span><br />
<button class="btn btn-default" type="submit">Submit</button>
</div>
</form>
</div>
</body>
</html>
任何人都可以引導我進入修復此?提交空白頁面時我沒有任何錯誤。
問題是此行'如果(mysqli_query){'。使用它作爲'if(mysqli_query($ conn,「INSERT INTO claim_info(.......)){echo」success!「;}' – Saty
'mysqli_query($ link,$ query)或者die(mysqli_error($鏈接))'會給你提供更好的信息是否有錯誤 – mitkosoft