所以我实际上对 MySQL 和 MySQLi 之间的区别了解不多,我会在工作的时候慢慢了解它...我正在尝试在这个新网站上使用我的旧 SQL PHP 注册表没有任何运气,我要么得到 "mysqli_query() expects at least 2 parameters, 1 given" 或空白页,要么返回站点错误,例如 "Desired Username is a required字段。请在下方输入。” 何时填写该字段?如果有人能看一看,我将不胜感激!谢谢。
注册.php -
<?php
if (isset($_GET['signuperror'])) {
$signuperror = $_GET['signuperror'];
} else {//if there is no choice, display series 1
$signuperror = 1;
}
switch($signuperror) {
case 1:
echo '';
break;
case 2:
echo "<div class='alert alert-danger'><strong>First Name is a required field. Please enter it below.</strong></span></div> ";
break;
case 3:
echo "<div class='alert alert-danger'><strong>Last Name is a required field. Please enter it below.</strong></span></div> ";
break;
case 4:
echo "<div class='alert alert-danger'><strong>Email Address is a required field. Please enter it below.</strong></span></div> ";
break;
case 5:
echo "<div class='alert alert-danger'><strong>Desired Username is a required field. Please enter it below.</strong></span></div> ";
break;
case 6:
echo "<div class='alert alert-danger'><strong>Your passwords do NOT match, please check your passwords.</strong></span></div> ";
break;
case 7:
echo "<div class='alert alert-danger'><strong>Your email address has already been used by another user. Please use a different Email address.</strong></span></div> ";
break;
case 8:
echo "<div class='alert alert-danger'><strong>The username you have selected has already been used by another user. Please choose a different Username.</strong></span></div> ";
break;
case 9:
echo "<div class='alert alert-danger'><strong>There has been an error creating your account. Please contact the admin.</strong></span></div> ";
break;
default:
break;
}
?>
<form name="register" id="register" action="registercode.php" method="POST">
<div class="register-top-grid">
<h3>PERSONAL INFORMATION</h3>
<div class="wow fadeInLeft" data-wow-delay="0.4s">
<span><b>First Name</b><label>*</label></span>
<input type="text" value="" data-msg-required="Please enter your first name." maxlength="100" name="first_name" id="first_name" required>
</div>
<div class="wow fadeInRight" data-wow-delay="0.4s">
<span><b>Last Name</b><label>*</label></span>
<input type="text" value="" data-msg-required="Please enter your last name." maxlength="100" name="last_name" id="last_name" required>
</div>
<div class="wow fadeInRight" data-wow-delay="0.4s">
<span><b>Email Address</b><label>*</label></span>
<input type="email" value="" data-msg-required="Please enter your email address." data-msg-email="Please enter a valid email address." size="68" name="email_address" id="email" required>
</div>
<div class="clearfix"> </div>
<a class="news-letter" href="#">
<label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i>Sign Up for Newsletter</label>
</a>
</div>
<div class="register-bottom-grid">
<h3>LOGIN INFORMATION</h3>
<div class="wow fadeInLeft" data-wow-delay="0.4s">
<span><b>Username</b><label>*</label></span>
<input type="text" value="" data-msg-required="Please enter a valid username." maxlength="100" name="username" id="username" required>
</div><div class="clearfix"> </div><div class="clearfix"> </div><div class="clearfix"> </div><div class="clearfix"> </div>
<div class="wow fadeInLeft" data-wow-delay="0.4s">
<span><b>Password</b><label>*</label></span>
<input type="password" value="" name="password" id="password" required>
</div>
<div class="wow fadeInRight" data-wow-delay="0.4s">
<span><b>Confirm Password</b><label>*</label></span>
<input type="password" value="" name="passwordcheck" id="passwordcheck" required>
</div>
</div>
<div class="clearfix"> </div>
<div class="register-but">
<input type="submit" value="REGISTER" class="btn btn-info"> | Already a member? <a href="signin.php"><b>Login</b></a>
<div class="clearfix"> </div>
</form>
</div>
</div>
</div>
</div>
<!-- registration -->
注册码.php -
<?
include 'core/init.php';
// Define post fields into simple variables
$first_name = mysqli_real_escape_string($_POST['first_name']);
$last_name = mysqli_real_escape_string($_POST['last_name']);
$email_address = mysqli_real_escape_string($_POST['email_address']);
$username = mysqli_real_escape_string($_POST['username']);
$password = $_POST['password'];
$passwordcheck = $_POST['passwordcheck'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
/* Do some error checking on the form posted fields */
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$password) || (!$passwordcheck)){
if(!$first_name){
header('Location: register.php?signuperror=2');
}
if(!$last_name){
header('Location: register.php?signuperror=3');
}
if(!$email_address){
header('Location: register.php?signuperror=4');
}
if(!$username){
header('Location: register.php?signuperror=5');
}
if ($password !== $passwordcheck){
header('Location: register.php?signuperror=6');
}
include "register.php"; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
$sql_email_check = mysqli_query($conn, "SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysqli_query($conn, "SELECT username FROM users WHERE username='$username'");
$email_check = mysqli_num_rows($sql_email_check);
$username_check = mysqli_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
if($email_check > 0){
header('Location: register.php?signuperror=7');
unset($email_address);
}
if($username_check > 0){
header('Location: register.php?signuperror=8');
unset($username);
}
include 'register.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
/* Everything has passed both error checks that we have done.
It's time to create the account! */
$db_password = md5($password);
// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysqli_query($conn, "INSERT INTO users (email_address, username, first_name, last_name, password, reg_date, last_login, activated, admin)
VALUES('$email_address', '$username', '$first_name', '$last_name', '$db_password', now(), now(), '0', '0')") or die (mysqli_error());
if(!$sql){
header('Location: register.php?signuperror=9');
} else {
$userid = mysqli_insert_id();
// Let's mail the user!
$subject = "Fundfeeder Accounts";
$message = "Dear $first_name $last_name,
Thank you for registering at Fundfeeder, http://www.fundfeeder.co.uk/
You are one step away from logging in and accessing your account.
To activate your membership, please click here: http://www.fundfeeder.co.uk/activate.php?id=$userid&code=$db_password
Once you activate your memebership, you will be able to login with the information you provided.
Thanks!
FundFeeder Admin Team.
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: FundFeeder Accounts<admin@fundfeeder.co.uk>\nX-Mailer: PHP/" . phpversion());
////// MAIL ADMIN
$subject2 = "FundFeeder New User!";
$message2 = "Dear Admin,
This is a message to alert you that a new user has signed up to FundFeeder.
You can view all details of the new member and all other members direct from the admin control panel at http://fundfeeder.co.uk/admin.php
Here are the details of the new registered user:
Username: $username
Email Address: $email_address
Thanks!
FundFeeder Accounts.
This is an automated response, please do not reply!";
mail('aidan6141@hotmail.co.uk', $subject2, $message2, "From: FundFeeder Accounts<admin@fundfeeder.co.uk>\nX-Mailer: PHP/" . phpversion());
header('Location: signin.php?loginerror=6');
include 'signin.php';
}
?>
core/init.php(数据库连接)-
<?php
$conn = mysqli_connect("mysql.hostinger.co.uk","u479096627_admin","password", "u479096627_ctrl");
//Evaluate the connection
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}
?>
最佳答案
您需要将数据库连接定义为所有 msqli_connect 语句的参数。
示例在这里:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$db ="database";
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
现在将查询传递给 msqli_query 时:
$query = "your-SQL-query";
$run = msqli_query($conn,$query);
if(!$run){
//handle the error here if query fails
}
要检查任何已存在的行,您需要传递以下内容
在本示例中,它将是:
$row_check = mysqli_num_rows($run);
希望您现在了解如何使用 msqli* 函数。
关于php - 更新到 SQLi 时 MySQL 注册不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29988994/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
作为新的阿里云用户,您可以50免费试用多种优惠,价值高达1,700美元(或8,500美元)。这将让您了解和体验阿里云平台上提供的一系列产品和服务。如果您以个人身份注册免费试用,您将获得价值1,700美元的优惠。但是,如果您是注册公司,您可以选择企业免费试用,提交基本信息通过企业实名注册验证,即可开始价值$8,500的免费试用!本教程介绍了如何设置您的帐户并使用您的免费试用版。关于免费试用在我们开始此试用之前,您还必须遵守以下条款和条件才能访问您的免费试用:只有在一年内创建的账户才有资格获得阿里云免费试用。通过此免费试用优惠,用户可以免费试用免费试用活动页面上列出的每种产品一次。如果您有多个帐
我正在尝试为我的iOS应用程序设置cocoapods但是当我执行命令时:sudogemupdate--system我收到错误消息:当前已安装最新版本。中止。当我进入cocoapods的下一步时:sudogeminstallcocoapods我在MacOS10.8.5上遇到错误:ERROR:Errorinstallingcocoapods:cocoapods-trunkrequiresRubyversion>=2.0.0.我在MacOS10.9.4上尝试了同样的操作,但出现错误:ERROR:Couldnotfindavalidgem'cocoapods'(>=0),hereiswhy:U
我在我的项目中有一个用户和一个管理员角色。我使用Devise创建了身份验证。在我的管理员角色中,我没有任何确认。在我的用户模型中,我有以下内容:devise:database_authenticatable,:confirmable,:recoverable,:rememberable,:trackable,:validatable,:timeoutable,:registerable#Setupaccessible(orprotected)attributesforyourmodelattr_accessible:email,:username,:prename,:surname,:
这太简单了,太荒谬了,我在任何地方都找不到关于它的任何信息,包括API文档和Rails源代码:我有一个:belongs_to关联,我开始理解当您没有关联时您在Controller中调用的正常模型方法与您有关联时调用的方法略有不同。例如,我的关联在创建Controller操作时运行良好:@user=current_user@building=Building.new(params[:building])respond_todo|format|if@user.buildings.create(params[:building])#etcetera但我找不到关于更新如何工作的文档:@user
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o
我看到其他人也遇到过类似的问题,但没有一个解决方案对我有用。0.3.14gem与其他gem文件一起存在。我已经完全按照此处指示完成了所有操作:https://github.com/brianmario/mysql2.我仍然得到以下信息。我不知道为什么安装程序指示它找不到include目录,因为我已经检查过它存在。thread.h文件存在,但不在ruby目录中。相反,它在这里:C:\RailsInstaller\DevKit\lib\perl5\5.8\msys\CORE\我正在运行Windows7并尝试在Aptana3中构建我的Rails项目。我的Ruby是1.9.3。$gemin