剛寫完測試時很順,資料也可以順入插入資料庫
但重整後,就會開始報錯無法執行,也看不到網頁的頁面
報的錯為:Fatal error: Uncaught mysqli_sql_exception:Column 'Location' cannot be null
想請各位幫幫忙QQ
已經debug一整天了
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Register</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/style.css">
<!-- Modernizr JS -->
<script src="js/modernizr-2.6.2.min.js"></script>
<!-- FOR IE9 below -->
<!--[if lt IE 9]>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>
<style>
.error {color: #FF0000;}
</style>
<body>
<?php
$accountErr = $passwordErr = "";
require_once("connect.php");
@$f_name = $_POST["fname"];
@$l_name = $_POST["lname"];
@$account = $_POST["account"];
@$phone_num = $_POST["phone_num"];
@$password = $_POST["password"];
@$re_password = $_POST["re-password"];
@$latitude = $_POST["latitude"];
@$longitude = $_POST["longitude"];
//檢查帳號是否重複
$check = "SELECT * FROM user WHERE Account = '$account'";
if (mysqli_num_rows(mysqli_query($conn, $check)) != 0){
$accountErr = "Account has been registered !!!";
exit();
}
else{
//驗證密碼
if($password != $re_password){
$passwordErr = "兩次密碼不同";
exit();
}
else{
$hash_passsword = hash("sha256", $password);
}
//$latlon = 'POINT(' . $longitude. " " . $latitude. ')';
$sql = "INSERT INTO `user`(`Account`, `Password`, `First_name`, `Last_name`, `Location`, `Phone_number`)
VALUES('".$account."', '".$hash_passsword."', '".$f_name."', '".$l_name."', ST_GeomFromText('POINT(" . $longitude. ' ' .$latitude. ")', 0), '".$phone_num."')";
if(mysqli_query($conn, $sql)){
echo "<script>alert('Register success !!')</script>";
header("refresh:1; url=login.php");
exit();
}
else{
echo "Error creating table: " . mysqli_error($conn);
}
}
?>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<!-- Start Sign In Form -->
<form method = "POST" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="fh5co-form animate-box" data-animate-effect="fadeIn">
<h2>Sign Up</h2>
<!-- <div class="form-group">
<div class="alert alert-success" role="alert">Your info has been saved.</div>
</div> -->
<div class="form-group">
<label for="fname" class="sr-only">First Name</label>
<input type = "text" class="form-control" id="fname" name = "fname" placeholder="FIRST NAME" autocomplete="off" required>
</div>
<div class="form-group">
<label for="lname" class="sr-only">Last Name</label>
<input type = "text" class="form-control" id="lname" name = "lname" placeholder="LAST NAME" autocomplete="off" required>
</div>
<div class="form-group">
<label for="phonenumber" class="sr-only">PhoneNumber</label>
<input type = "text" name = "phone_num" class="form-control" id="phonenumber" placeholder="PHONENUMBER" autocomplete="off" pattern = "\d{10}$" required>
</div>
<div class="form-group">
<label for="Account" class="sr-only">Account</label>
<input type = "text" class="form-control" id="Account" name = "account" placeholder="ACCOUNT" autocomplete="off" pattern = "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$" required>
包含大小寫字母和數字的組合且長度在8-16之間
<span class = "error"><?php echo $accountErr;?></span>
</div>
<div class="form-group">
<label for="password" class="sr-only">Password</label>
<input type = "password" class="form-control" id="password" name = "password" placeholder="PASSWORD" autocomplete="off" pattern = "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$" required>
包含大小寫字母和數字的組合且長度在8-16之間
<span class = "error"><?php echo $passwordErr;?></span>
</div>
<div class="form-group">
<label for="re-password" class="sr-only">Re-type Password</label>
<input type = "password" class="form-control" id="re-password" name = "re-password" placeholder="RE-TYPE PASSWORD" autocomplete="off" required>
<span class = "error"><?php echo $passwordErr;?></span>
</div>
<div class="form-group">
<label for="latitude" class="sr-only">latitude</label>
<input type = "text" class="form-control" id="latitude" name = "latitude" placeholder="LATITUDE" autocomplete="off" pattern = "^(-?\d+)(\.\d+)?$" required>
</div>
<div class="form-group">
<label for="longitude" class="sr-only">longitude</label>
<input type = "text" class="form-control" id="longitude" name = "longitude" placeholder="LONGITUDE" autocomplete="off" pattern = "^(-?\d+)(\.\d+)?$" required>
</div>
<div class="form-group">
<p>Already registered? <a href="login.php">Sign In</a></p>
</div>
<div class="form-group">
<input type="submit" value="Sign Up" class="btn btn-primary">
</div>
</form>
<!-- END Sign In Form -->
</div>
</div>
</div>
<!-- jQuery -->
<script src="js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- Placeholder -->
<script src="js/jquery.placeholder.min.js"></script>
<!-- Waypoints -->
<script src="js/jquery.waypoints.min.js"></script>
<!-- Main JS -->
<script src="js/main.js"></script>
</body>
我只想問,是誰這樣教你的。
如果是看書的。還是快把書給燒了。
如果是自已東抄西抄的。
請先了解一下何謂後端語言及何謂前端語言。
另外搞懂一下 form 的應用。
說真的,你這錯在哪我還真的沒辦法你指正。
因為錯太多,多到不知道該怎麼去救你。
column 'Location' cannot be null
表示你要插入資料庫的資料的 Location 欄位值是空的
要解決這個問題
就要先看你的 Location 的值
插入一列echo $sql
如下
$sql = "INSERT INTO `user`(`Account`, `Password`, `First_name`, `Last_name`, `Location`, `Phone_number`)
VALUES('".$account."', '".$hash_passsword."', '".$f_name."', '".$l_name."', ST_GeomFromText('POINT(" . $longitude. ' ' .$latitude. ")', 0), '".$phone_num."')";
echo $sql;
if(mysqli_query($conn, $sql)){
echo "<script>alert('Register success !!')</script>";
header("refresh:1; url=login.php");
exit();
}
else{
echo "Error creating table: " . mysqli_error($conn);
}