我有一个大学作业,我必须设计一个网站,我必须存储用户的详细信息。我做了一个谷歌搜索,我找到了一个脚本,适用于我的注册页面因此,我复制了该脚本的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
没有工作:( –