我正在尝试建立社交网络数据库,但是在将值插入user_
表中时遇到一些问题。
数据库已经存在,但没有更新(重定向到PHP/signup.php
时没有输出代码),也没有新行受到插入数据库的影响。
我是PHP
的新手,所以我想我有失误,但我无法弄清楚,请帮助我。
我的文件租用者是
-css
-js
-img
-PHP
-- signup.php
-- login.php
-signup.html
-login.html
我的HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Signup for facebook! </title>
<link href='https://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel="stylesheet" href="css/signup.css">
</head>
<body>
<section class="logina-form-wrap">
<h1>Facebook</h1>
<form class="login-form" action="./PHP/signup.php" method="post">
<label>
<input type="text" name="firstName" required placeholder="First Name">
</label>
<label>
<input type="text" name="lastName" required placeholder="Last Name">
</label>
<label>
<input type="text" name="nickName" placeholder="Nick Name">
</label>
<label>
<input type="password" name="Password" required placeholder="Password">
</label>
<label>
<input type="tel" name="phoneNumber" placeholder="Phone">
</label>
<label>
<input type="email" name="Email" required placeholder="Email">
</label>
<label>
<input list="sex-s" name="sex" required placeholder="Sex">
<datalist id="sex-s">
<option value="Male">
<option value="Female">
<option value="Not determined">
</datalist>
</label>
<label>
<input type="date" name="bday" required placeholder="Birthday">
</label>
<label style="color:white;">
Upload your image!
<input id = "uploadBox" type="file" name="pic" accept="image/*">
</label>
<label>
<input type="text" name="homeTown" placeholder="Home Town">
</label>
<label>
<input list="marital" name="status" placeholder="Marital Status">
<datalist id="marital">
<option value="Single">
<option value="Engaged">
<option value="Married">
</datalist>
</label>
<label>
<textarea rows="4" cols="31" name="me" placeholder="About You." style="margin: 5px auto 0 auto;"></textarea>
</label>
<input type="submit" value="Register" name="register_">
</form>
</section>
</body>
</html>
我的PHP代码。
<?php
$servername = "localhost";
$username = "username";
$password = "";
$db="socialnetwork";
// Create connection
$conn = new mysqli($servername, $username, $password,$db);
// Check connection
if ($conn->connect_error)
{
echo("Failed");
die("Connection failed: " . mysqli_connect_error());
}
else
{
echo("?");
if (isset($_POST['register_']))
{
$firstname=$_POST['firstName'];
$lastname=$_POST['lastName'];
$nickname=$_POST['nickName'];
$password=$_POST['Password'];
$email=$_POST['Email'];
$gender=$_POST['sex'];
$hometown=$_POST['homeTown'];
$phone=$_POST['phoneNumber'];
$birtdate=$_POST['bday'];
$aboutme=$_POST['me'];
$mstatus=$_POST['status'];
$image=$_FILES['pic']['name'];
if ($_FILES['pic']['name'] == ""){
if($gender == 1){
$image = "./img/female_default";
}
else{
$image = "./img/male_default";
}
}
$sql="INSERT INTO user_(first_name, last_name, nick_name, pass_word, user_email, phone_number, home_town, about_me, user_status, birth_date, user_gender, number_friends, user_image) VALUES ('$firstname','$lastname','$nickname','$password','$email','$phone','$hometown','$aboutme','$mstatus','$birtdate','$gender', 10, '$image')";
$qry=mysqli_query($conn,$sql);
if($qry){
echo "done";
}
}
$conn->close();
}
?>
我的SQL文件
create database socialnetwork;
CREATE TABLE if not exists user_(
first_name varchar(255) not null,
last_name varchar(255) not null,
nick_name varchar(255),
pass_word varchar not null,
user_email varchar(255) unique not null,
phone_number varchar(255),
home_town varchar(255) ,
about_me varchar(255) ,
user_status varchar(255),
birth_date varchar(255),
user_gender varchar(255),
number_friends int ,
user_image VARBINARY (10000000),
PRIMARY KEY (user_email)
);
答案 0 :(得分:0)
问题是:
您必须在htdocs
文件夹的XAMPP
文件夹中设置项目。