我无法将我的代码链接到我的PHP数据库 [英] I can't link my code to my PHP database

查看:128
本文介绍了我无法将我的代码链接到我的PHP数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作表上签名但是每当我按下注册时它会转到此链接



 {code:MethodNotAllowedError ,消息:不允许POST} 



我正在使用Dreamweaver 2017



这是我的代码



// Doc name signup.php

 <? php 
include_once ' Header.php';
?>


< < span class =code-leadattribute> section class = 主要容器 >
< div class = main-wrapper >
< h2 > 注册< / h2 >





注册


< / div >



< / section >

<? php
include_once ' footer.php';
?>



//signup.inc.php

 <?php  

if (isset($ _ POST [' submit'])){

include_once ' dbh.inc.php';

$ first = mysqli_real_escape_string($ conn,$ _POST [' 第一]);
$ last = mysqli_real_escape_string($ conn,$ _POST [' 最后']);
$ email = mysqli_real_escape_string($ conn,$ _POST [' 电子邮件']);
$ uid = mysqli_real_escape_string($ conn,$ _ POST [' UID']);
$ pwd = mysqli_real_escape_string($ conn,$ _POST [' PWD']);

{
header( 位置:../ signup.php?signs =空);
exit();

// 错误hsndlers
// Chack for empty fields
if (空( $ first)|| empty($ last)|| empty($ email)|| empty($ uid)|| empty($ pwd)){
exit();
} 其他 {
// 检查输入字符是否有效
如果(!preg_match( < span class =code-string> / ^ [a-zA-Z] * $ /
,$ first)||!preg_match( / ^ [a-zA-Z] * $ /,$ last)){


header( 位置:../ signup.php?signup = invalid);
exit();
} else {

// 检查电子邮件是否有效

如果(!filter_var($ email,FILTER_VALIDATE_EMAIL)){
header( 位置:../ signup.php?signup = invalidemail);
exit();

} else {
$ sql = SELECT * FROM users WHERE user_uid ='$ uid';
$ result = mysql_query($ conn,$ sql);
$ resultCheck + mysqli_num_rows($ result);

if ($ resultCheck> 0){
header( 位置:../ signup.php?signup = usertaken);
exit();


}其他{
// 哈希密码
$ hashedPwd = password_hash($ pwd,PASSWORD_DEFAULT);
// 将用户插入数据库

$ sql = INSERT INTO用户(user_first,user_last,user_email,user ,pwd)VALUES('$ first','$ last','$ email','$ uid''$ hashedPwd');;

mysqli_query($ conn,$ sql);
header( 位置:../ signup.php?signup = success);
exit();

}
}

}

} 其他 {
header( Location:../ signup.php);
exit();

}



//dbh.inc.php

 <?php  

$ dbServername = localhost;
$ dbUsername = root;
$ dbPassword = ;
$ dbName = servername_loginsystem;

$ conn = mysqli_connect($ dbServername,$ dbUsername,$ dbPassword,$ dbName);





我尝试过:



我检查过语法错误,重命名服务器,安装XAMPP(我想我做得很好)。仅供参考我是php的新手,所以它可能很简单。

解决方案

_POST [' submit'])){

include_once ' dbh.inc.php';


first = mysqli_real_escape_string(


conn,

I made a sign in sheet but whenever I press signup It goes to this link

{"code":"MethodNotAllowedError","message":"POST is not allowed"}


I'm using Dreamweaver 2017

here is my code

//Doc name signup.php

<?php
	include_once 'Header.php';
?>
		
								
		<section class="main-container">
			<div class="main-wrapper">
			  <h2> Signup </h2>
			  
				

					
					
					Sign up 
					 
				
			</div>
			
			
			
		</section>
	
<?php
	include_once 'footer.php';
?> 


//signup.inc.php

<?php

if (isset($_POST['submit'])) {
	
	include_once 'dbh.inc.php';
	
	$first = mysqli_real_escape_string($conn, $_POST['first']);
	$last = mysqli_real_escape_string($conn, $_POST['last']);
	$email = mysqli_real_escape_string($conn, $_POST['email']);
	$uid = mysqli_real_escape_string($conn, $_POST['uid']);
	$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
	
	 {
	header("Location: ../signup.php?signup=empty");
	exit();
	
	//Error hsndlers
	//Chack for empty fields
	if (empty($first) || empty($last)|| empty($email)|| empty($uid)|| empty($pwd)) {
		exit();
	} else {
		//Check if input charecters are valid
		if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last) ) {
			
			
				header("Location: ../signup.php?signup=invalid");
				exit();
		} else {
			
			 //Check if email is valid
			
			if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
				header("Location: ../signup.php?signup=invalidemail");
				exit();
				
			} else {
				$sql = "SELECT * FROM users WHERE user_uid='$uid'";
				$result = mysql_query($conn, $sql);
				$resultCheck + mysqli_num_rows($result);
				
				if ($resultCheck > 0) {
					header("Location: ../signup.php?signup=usertaken");
					exit();
					
				
				}else{
					//hashing password
					$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
					//Insert the user to database
				
					$sql = "INSERT INTO users (user_first, user_last,user_email, user,pwd) VALUES ('$first', '$last', '$email', '$uid' '$hashedPwd');";
				
					mysqli_query($conn, $sql);
					header("Location: ../signup.php?signup=success");
					exit();
					
		}
	}
	
}
	
} else {
	header("Location: ../signup.php");
	exit();

}


//dbh.inc.php

<?php

$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "servername_loginsystem";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);



What I have tried:

I've checked for syntax errors, renaming server, installing XAMPP(I think I did it properly). FYI i'm new to php so it might be something simple.

解决方案

_POST['submit'])) { include_once 'dbh.inc.php';


first = mysqli_real_escape_string(


conn,


这篇关于我无法将我的代码链接到我的PHP数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆