-- register.php --
<form id='form' action="../function/process_reg.php" method="post">
<input type="text" class="form-control" name="id" id="form-title" placeholder="ID">
<input type="password" class="form-control" name="pw" id="form-title" placeholder="PASSWORD">
<input type="text" class="form-control" name="nickname" id="form-title" placeholder="NICKNAME">
<input type="submit" name="name" class="btn btn-default btn-lg" value='회원가입'>
-- process_reg.php --
<?php
require("../config/config.php");
require("../lib/db.php");
require("../lib/password.php");
require("../lib/codegen.php");
$conn = db_init($config["host"],$config["duser"],$config["dpw"],$config["dname"]);
$id = $_POST['id'];
$nickname = $_POST['nickname'];
$sql = 'INSERT INTO userdata (id,pw,nickname,pid) VALUES("'.$id.'","'. password_hash($_POST['pw'], PASSWORD_DEFAULT).'", "'.$nickname.'",.generateRenStr(10).)';
$result = mysqli_query($conn, $sql);
header('Location: ../login/login.php');
?>
-- config.php --
<?php
$config = array(
"host" => 'localhost',
"duser" => 'root',
"dpw" => "B32bpu98",
"dname" => "sid_userdata",
);
?>
-- db.php --
<?php
function db_init($host, $duser, $dpw, $dname){
$conn = mysqli_connect($host,$duser,$dpw);
mysqli_select_db($conn, $dname);
return $conn;
}
?>
-- codegen.php --
<?
function generateRenStr($length) {
echo 'helloworld';
$character = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$rendom_str = "";
$loopNum = $length;
while ($loopNum--) {
$rendom_str .= $character(mt_rand(0, strlen($character)));
}
return $rendom_str;
}
?>
此代码在浏览器上不会出现错误,但它不会向sql server发送数据。我无法找到它发生的原因。我认为codegen.php有错误。我没有编写codegen.php和password.php。所以我无法修复它。