我有一個大學作業,我必須設計一個網站,我必須存儲用戶的詳細信息。我做了一個谷歌搜索,我找到了一個腳本,適用於我的註冊頁面因此,我複製了該腳本的index.php頁面,並且我已經使用wampserver在phpymadmin中創建了一個表格聯繫人,並且插入了3列用戶名,電子郵件,消息。但是現在,當我試圖輸入一些細節並單擊提交按鈕時,頁面正在刷新並且數據未存儲在數據庫中。如何使用wampserver在php中存儲用戶的數據?
<form role="form" method="post" action="index.php">
\t <!-- Name -->
\t <div class="row">
\t \t <div class="col-md-6">
\t \t \t <div class="form-group">
\t \t \t \t <input type="text" class="form-control" placeholder="Your name" name="name">
\t \t \t </div>
\t \t </div>
\t \t <!-- E-Mail -->
\t \t <div class="col-md-6">
\t \t \t <div class="form-group">
\t \t \t \t <input type="email" class="form-control" placeholder="Email address" name="email">
\t \t \t </div>
\t \t </div>
\t </div>
\t <!-- Message Area -->
\t <div class="form-group">
\t \t <textarea class="form-control" name="message" placeholder="Write you message here..." style="height:232px;"></textarea>
\t </div>
\t <!-- Subtmit Button -->
\t <button type="submit" class="btn btn-send" value="register">
\t \t Send message
\t </button>
</form>
<?php
include("contact.php");//make connection here
if(isset($_POST['register']))
{
$Username=$_POST['name'];//here getting result from the post array after submitting the form.
$Email=$_POST['email'];//same
$Message=$_POST['message'];//same
if($Username=='')
{
//javascript use for input checking
echo"<script>alert('Please enter the name')</script>";
exit();//this use if first is not work then other will not show
}
if($Email=='')
{
echo"<script>alert('Please enter the email')</script>";
exit();
}
if($Message=='')
{
echo"<script>alert('Please enter the message')</script>";
exit();
}
//here query check weather if user already registered so can't register again.
$check_email_query="select * from contact WHERE Email='$Email'";
$run_query=mysqli_query($dbcon,$check_email_query);
if(mysqli_num_rows($run_query)>0)
{
echo "<script>alert('Email $user_email is already exist in our database, Please try another one!')</script>";
exit();
}
//insert the user into the database.
$insert_user="insert into contact (Username,Email,Message) VALUE ('$Username','$Email','$Message')";
if(mysqli_query($dbcon,$insert_user))
{
echo"<script>alert('Thank you for contacting us')</script>";
}
}
?>
變化'插入接觸(用戶名,電子郵件,留言)VALUE'爲'插入接觸(用戶名,電子郵件,留言)VALUES' –
'VALUE'應該是'VALUES'和你借一個非常貧窮的PHP代碼的例子**抄襲** – RiggsFolly
沒有工作:( –