从表中检查电子邮件和密码后,它应该进入 studentDashBoard.php 文件。但每次我都出错,它会给出错误的 id 或 psd 错误。
这是我的 html 标记:
登录.php:
<form action="login.php" id="LoginForm" name="LoginForm" method="post" onsubmit=" return validate();">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-user"></span></span>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" required>
</div>
<p id="statusEmail"></p>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-star"></span></span>
<input type="password" name="password"class="form-control" id="exampleInputPassword1" placeholder="Password" required>
</div>
<p id="statusPsd"></p>
</div>
<hr/>
<p id="status"></p>
<button type="button" class="btn btn-success"><span class="glyphicon glyphicon-arrow-left">Back</button>
<button type="submit" name="submit" id="loginButton" class="btn btn-primary"><span class="glyphicon glyphicon-lock">Login</button>
<p><br/></p>
<p id="notice"> If not registered yet</p><br/>
<button type="button" id="SignUp" class="btn btn-danger">SingUp</button>
</form>
这是 jQuery 代码:
$(document).ready(function(){
$("#loginButton").click(function(e){
email=$("#exampleInputEmail1").val();
e.preventDefault();
password=$("#exampleInputPassword1").val();
$.ajax({
type: "POST",
url: "StudentLogin.php",
data: "email="+email+"&password="+password,
success:function(html)
{
if(html==true){
---> this function is not working while I am login with correct data
window.location="studentDashBoard.php";
}
else{
$("#status").html("<p>worng id or psd</p>");
}
}
});
});
});
和StudentLogin.php代码
<?php
$link = mysqli_connect('localhost','root','','users');
if (!$link) {
die('Could not connect to MySQL: ' . mysqli_error($link));
}
if(isset($_POST['submit']))
{
echo "submit";
$email=$_POST['email'];
$password=$_POST['password'];
$sql = "SELECT * FROM student WHERE email='$email' AND password='$password' ";
$query = mysqli_query($link,$sql);
$result= mysqli_num_rows($query);
if($result > 0)
{
echo 'true';
}
else
{
echo 'false';
}
}
mysqli_close($link);
?>
studentDashBoard.php 文件只是打印“hi”,没有别的。
如果您需要更多详细信息,请告诉我
最佳答案
代替:
if(isset($_POST['submit'])){
在 studentLogin.php 文件中,我更改为
if(isset($_POST['email']) && isset($_POST['password']) )
{
现在可以了
关于php - if(html==true) 不满足这个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30944822/
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我正在检查一个Rails项目。在ERubyHTML模板页面上,我看到了这样几行:我不明白为什么不这样写:在这种情况下,||=和ifnil?有什么区别? 最佳答案 在这种特殊情况下没有区别,但可能是出于习惯。每当我看到nil?被使用时,它几乎总是使用不当。在Ruby中,很少有东西在逻辑上是假的,只有文字false和nil是。这意味着像if(!x.nil?)这样的代码几乎总是更好地表示为if(x)除非期望x可能是文字false。我会将其切换为||=false,因为它具有相同的结果,但这在很大程度上取决于偏好。唯一的缺点是赋值会在每次运行
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
假设我在Ruby中有这个each循环。@list.each{|i|putsiifi>10breakend}我想循环遍历列表直到满足条件。这让我感到“不像Ruby”,因为我是Ruby的新手,是否有Ruby方法可以做到这一点? 最佳答案 您可以使用Enumerable#detect或Enumerable#take_while,取决于您想要的结果。@list.detect{|i|putsii>10}#Returnsthefirstelementgreaterthan10,ornil.正如其他人所指出的,更好的风格是先进行子选择,然后再对其
我正在学习http://ruby.railstutorial.org/chapters/static-pages上的RubyonRails教程并遇到以下错误StaticPagesHomepageshouldhavethecontent'SampleApp'Failure/Error:page.shouldhave_content('SampleApp')Capybara::ElementNotFound:Unabletofindxpath"/html"#(eval):2:in`text'#./spec/requests/static_pages_spec.rb:7:in`(root)'