嘿,对不起,如果这个问题可能被问得太多,但我在网站上看到的问题都没有帮助我,而且标题指出我有一个插入查询,可以为我正在制作的网站创建一个帐户但是当我按下提交按钮时它什么都不做......只需刷新页面。
注意:包括数据库。 网站的这一部分包含在signup.php中,而在signup.php中包含了连接文件。 经过测试后我可以从connect.php中获取,所以我不认为那是问题所在。 尽管这并不能证明为什么代码不会一直运行。
经过故障排除和测试后,我发现删除了这部分代码:
if (
$username_error_message_status = false
and $password_error_message_status = false
and $email_error_message_status = false
and $bot_check_error_message_status = false
) {
代码工作但插入查询语句没有。因此,任何形式的帮助都将受到赞赏并感谢阅读。
完整代码:
<?php
$sign_up_button = isset($_POST["sign_up_button"]);
$username_error_message = $password_error_message = $email_error_message = $bot_check_error_message = "";
$username_error_message_status = $password_error_message_status = $email_error_message_status = $bot_check_error_message_status = "";
$username_field = $email_field = "";
if ($sign_up_button) {
$username_field = $_POST["sign_up_username"];
$password_field = $_POST["sign_up_password"];
$email_field = $_POST["sign_up_email"];
$bot_check_field = isset($_POST["sign_up_bot_check"]);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($username_field)) {
$username_error_message_status = true;
$username_error_message = "This field is required.";
}
else {
$username_error_message_status = false;
}
if (empty($password_field)) {
$password_error_message_status = true;
$password_error_message = "This field is required.";
}
else {
$password_error_message_status = false;
}
if (empty($email_field)) {
$email_error_message_status = true;
$email_error_message = "This field is required.";
}
else {
$email_error_message_status = false;
}
if ($bot_check_field < 100) {
$bot_check_error_message_status = true;
$bot_check_error_message = "Please slide the slider to the end.";
}
else {
$bot_check_error_message_status = false;
}
}
if (
$username_error_message_status = false
and $password_error_message_status = false
and $email_error_message_status = false
and $bot_check_error_message_status = false
) {
/* --- --- --- --- --- --- --- --- Check username availability --- --- --- --- --- --- --- --- */
$check_username_query = "SELECT `Username` FROM `users` WHERE `Username` = '$username_field' ";
$check_username_query_result = mysqli_query($GLOBALS["___mysqli_ston"], $check_username_query);
$numrows_check_username_query_result = mysqli_num_rows($check_username_query_result);
if ($numrows_check_username_query_result == 1) {
$username_availability_status = false;
?>
<p><span class = "sign-up-error-tag">That username already exists in our database. Please choose another.</span></p>
<?php
}
else {
$username_availability_status = true;
}
/* --- --- --- --- --- --- --- --- Check email availability --- --- --- --- --- --- --- --- */
$check_email_query = "SELECT `Email` FROM `users` WHERE `Email` = '$email_field' ";
$check_email_query_result = mysqli_query($GLOBALS["___mysqli_ston"], $check_email_query);
$numrows_check_email_query_result = mysqli_num_rows($check_email_query_result);
if ($numrows_check_email_query_result == 1) {
$email_availability_status = false;
?>
<p><span class = "sign-up-error-tag">That email already exists in our database. Please choose another.</span></p>
<?php
}
else {
$email_availability_status = true;
}
/* --- --- --- --- --- --- --- --- Check email validity --- --- --- --- --- --- --- --- */
if (filter_var($email_field, FILTER_VALIDATE_EMAIL)) {
$email_validity_status = true;
}
else {
$email_validity_status = false;
?>
<span class = "sign-up-error-tag">That email is invalid. Please choose another.</span>
<?php
}
/* --- --- --- --- --- --- --- --- Hashing password --- --- --- --- --- --- --- --- */
function better_crypt($input, $rounds = 7) {
$salt = "";
$salt_chars = array_merge(range('A','Z'), range('a','z'), range(0,9));
for($i=0; $i < 22; $i++) {
$salt .= $salt_chars[array_rand($salt_chars)];
}
return crypt($input, sprintf('$2a$%02d$', $rounds) . $salt);
}
$password_field_hash = better_crypt($password_field);
$password_field_hash = better_crypt($password_field, 10);
$password_field_hash = better_crypt($password_field, 15);
/* --- --- --- --- --- --- --- --- Create account in database --- --- --- --- --- --- --- --- */
$sign_up_date = date("Y-m-d h:i:sa");
$sign_up_code = rand();
$sign_up_active_status = "0";
$create_account_query = mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO `users`(`Username`, `Email`, `Password`, `RegisterCode`, `Date`, `ActiveStatus`) VALUES ('$username_field', '$email_field', '$password_field_hash', '$sign_up_code', '$sign_up_date', '$sign_up_active_status')");
/* --- --- --- --- --- --- --- --- Send activation email --- --- --- --- --- --- --- --- */
$email_to = $email_field;
$WebsiteName = "ForTheHodor";
$email_message = "
<table width='100%' border='0' cellspacing='0' cellpadding='3'>
<tr>
<td colspan=2><b>".$WebsiteName."</b></td>
</tr>
<tr>
<td colspan=2>Thank you for creating an account.</td>
</tr>
</table>
<hr><h3>Account info</h3><hr>
<table width='100%' border='0' cellspacing='0' cellpadding='3'>
<tr>
<td width='28%' >Username : </td>
<td width='72%'>".$username_field."</td>
</tr>
<tr>
<td>Email : </td>
<td>".$email_field."</td>
</tr>
</table>
<p>".$WebsiteName." advise you not to delete this email for it contains informations that could be in use later.</p>
<hr><h3>Account activation</h3><hr>
<p>If you wish to activate your account please use the following link : </p>
<p><a href = 'localhost/SignalShare/activate.php' style = 'text-decoration: none; color: blue;' >Activate account</a></p>
<p>Activiation code :</p>
<p>".$sign_up_code."</p>
<hr>
<p>If this email does not concern you please ignore it.</p>
<p>All regards.</p>
<p>".$WebsiteName."</p>
";
$email_subject = "Accout activation";
$email_headers = "From:".$WebsiteName."\r\n";
$email_headers .= "Content-type: text/html\r\n";
mail($email_to, $email_subject, $email_message, $email_headers);
echo $email_message;
}
}
?>
<div id = "SignupForm">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Sign up</h3>
</div>
<div class="panel-body">
<span>
<form method = "POST" action= "signup.php">
<table class = "table table-borderless">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class = "Sign-up-tag">Username</span>
</td>
<td>
<input type = "text" name = "sign_up_username" class = "sign-up-field" value = "<?php echo $username_field; ?>"></input>
</td>
</tr>
<tr>
<td>
</td>
<td>
<span class = "sign-up-error-tag"><b><?php echo $username_error_message; ?></b></span>
</td>
</tr>
<tr>
<td>
<span class = "Sign-up-tag">Password</span>
</td>
<td>
<input type = "password" name = "sign_up_password" class = "sign-up-field"></input>
</td>
</tr>
<tr>
<td>
</td>
<td>
<span class = "sign-up-error-tag"><b><?php echo $password_error_message; ?></b></span>
</td>
</tr>
<tr>
<td>
<span class= "Sign-up-tag">Email</span>
</td>
<td>
<input type = "text" name = "sign_up_email" class = "sign-up-field" value = "<?php echo $email_field; ?>"></input>
</td>
</tr>
<tr>
<td>
</td>
<td>
<span class = "sign-up-error-tag"><b><?php echo $email_error_message; ?></b></span>
</td>
</tr>
<tr>
<td>
<span class= "Sign-up-tag">Bot check</span>
</td>
<td>
<input id= "defaultSlider" type="range" min="0" max="100" value = "0" name = "sign_up_bot_check"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<span class = "sign-up-error-tag"><b><?php echo $bot_check_error_message; ?></b></span>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type = "submit" name = "sign_up_button" class="btn btn-success" value = "Sign up"></input>
</td>
</tr>
</tbody>
</table>
</form>
</span>
</div>
</div>
</div>
表格shema:
-- phpMyAdmin SQL Dump
-- version 4.5.5.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 12, 2016 at 07:59 AM
-- Server version: 5.7.11
-- PHP Version: 5.6.19
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `forthehodor`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`ID` int(11) NOT NULL,
`Username` varchar(32) NOT NULL,
`Email` varchar(45) NOT NULL,
`Password` varchar(32) NOT NULL,
`RegisterCode` varchar(50) NOT NULL,
`Date` varchar(50) NOT NULL,
`ActiveStatus` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`ID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
答案 0 :(得分:1)
您的删除if if query应如下所示:
if (
$username_error_message_status == false
and $password_error_message_status == false
and $email_error_message_status == false
and $bot_check_error_message_status == false
) {
如果要比较值,则需要在if语句中使用double equals(==
)而不是单个(=
)。