我对PHP非常陌生,所以我尝试不同的方式让我的selft更精通。 在这里,我试图将数据保存到数据库,但我不能这样做,数据在注册期间没有保存在数据库中。
这是我的代码。
<?php
$connection=mysqli_connect("localhost","root","");
$connection=mysqli_select_db("cinderella");
or die(mysqli_error($connection));
?>
<?php
include('config.php');
if(isset($_POST['action']))
{
if($_POST['action']=="signup")
{
$name = mysqli_real_escape_string($connection,$_POST['name']);
$email = mysqli_real_escape_string($connection,$_POST['email']);
$password = mysqli_real_escape_string($connection,$_POST['password']);
$phone = mysqli_real_escape_string($connection,$_POST['phone']);
$country = mysqli_real_escape_string($connection,$_POST['country']);
$city = mysqli_real_escape_string($connection,$_POST['city']);
$zip = mysqli_real_escape_string($connection,$_POST['zip']);
$query = "SELECT email FROM registration where email='".$email."'";
$result = mysqli_query($connection,$query);
$numResults = mysqli_num_rows($result);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) // Validate email address
{
$message = "Invalid email address please type a valid email!!";
}
elseif($numResults>=1)
{
$message = $email." Email already exist!!";
}
else
{
mysql_query("insert into registration(name,email,password,phone,country,city,zip) values('".$name."','".$email."','".md5($password)."','".$phone."','".$country."','".$city."','".$zip."')");
$message = "Signup Sucessfully!!";
}
}
}
?>
<html>
<script type="text/javascript" src="jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<body>
<form action="php/sign.php" method="post" class="signup">
<p><input id="name" name="name" type="text" placeholder="Name"></p>
<p><input id="email" name="email" type="text" placeholder="Email"></p>
<p><input id="password" name="password" type="password" placeholder="Password">
<p><input id="phone" name="phone" type="text" placeholder="phone"></p>
<p><input id="country" name="country" type="text" placeholder="country"></p>
<p><input id="city" name="city" type="text" placeholder="city"></p>
<p><input id="zip" name="zip" type="text" placeholder="zip"></p>
<input name="action" type="hidden" value="signup" /></p>
<div>
<center>
<span style="color:green;display:none;" class="sign-footer"><h4 style="margin-left: 0px;">Registered successfully .Please login </h4></span>
<span style="color:orange;display:none;" class="signerror-footer"><h4 style="margin-left: 0px;">Please check your email </h4></span>
</center>
</div>
<p><input type="submit" value="Signup" /></p>
</form>
<script type="text/javascript">
var frm = $('.signup');
frm.submit(function (ev) {
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
//alert(data);
if (data) {
//alert('data');
$('.sign-footer').css('display','block');
}
else{
$('.signerror-footer').css('display','block')
}
}
});
ev.preventDefault();
});
</script>
</body>
</html>
对此的任何帮助都会对我有所帮助,....谢谢......