我如何使用此HTML代码在PHP中连接并登录mysql localhost [英] How I can connect and login in mysql localhost in PHP by using this HTML code

查看:68
本文介绍了我如何使用此HTML代码在PHP中连接并登录mysql localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html> 
< html>
< head>
< meta charset =UTF-8>
< title>在线学生服务中心< / title>



< / head>

< body>

< body>
< div class =container>
< section>
< form action =php / login.phpmethod =POST>
< h1>登录表单< / h1>
< div>
< input type =textplaceholder =Student IDrequired =id =username/>
< / div>
< div>
< input type =passwordplaceholder =Passwordrequired =id =password/>
< / div>
< div>
< input type =submitvalue =登录/>
< a href =#>丢失了您的密码?< / a>
< a href =#>注册< / a>
< / div>
< / form><! - form - >
< div class =button>
< a href =admin.html> Admin< / a>
< / div><! - 按钮 - >

< div class =button>
< a href =teacher.html>老师< / a>
< / div><! - 按钮 - >

< / section><! - content - >
< / div><! - 容器 - >
< / body>

< script src =js / index.js>< / script>

< / body>
< / html>





我尝试过:



i希望通过使用以上html代码从测试数据库表学生登录

解决方案

我不知道你是不是只是在尝试通过php连接到mysql或者如果你试图通过mysql创建登录功能。



1)如果你想创建登录功能,你可以滚动这段代码你自己或找到一个现有的框架为你做这件事。



基本上你需要将用户名/密码传递给你的服务器端代码(看起来像login.php)和然后加密/哈希密码(假设你正在哈希你的密码),以便将它与数据库中的密码进行比较。



如果你没有哈希,然后从数据库中解密您的密码,并将键入的内容与数据库中存在的内容进行比较。如果它匹配,那么用户将通过身份验证。如果没有,则显示错误消息。



鉴于我对您的代码没有其他了解,我甚至无法开始提供代码示例或其他任何内容。你在做什么已经做了好几千次,而不是新的。您应该使用谷歌查找示例登录PHP代码并根据您的需要进行调整。将您的问题分解成更小的部分并开始实现您需要的东西。试图找到一个适合您的特定问题的互联网上的所有解决方案可能是一个非常不容易找到的东西。



您应该自己尝试创建代码,如果您遇到问题,请使用更好的代码示例,而不仅仅是显示html,这与您的内容几乎没有关系试图完成,并明确定义你正在解决的问题。



2)所以如何使用php连接到mysql



Google [ ^ ]



PHP连接到MySQL [ ^ ]



< a href =http://php.net/manual/en/function.mysql-connect.php> PHP:mysql_connect - Manual [ ^

<!DOCTYPE html>
<html >
  <head>
    <meta charset="UTF-8">
    <title>Online Student Service Center</title>
    
        
    
  </head>

  <body>

    <body>
<div class="container">
	<section>
		<form action="php/login.php" method="POST" >
			<h1>Login Form</h1>
			<div>
				<input type="text" placeholder="Student ID" required="" id="username" />
			</div>
			<div>
				<input type="password" placeholder="Password" required="" id="password" />
			</div>
			<div>
				<input type="submit" value="Log in" />
				<a href="#">Lost your password?</a>
				<a href="#">Register</a>
			</div>
		</form><!-- form -->
		<div class="button">
			<a href="admin.html">Admin</a>
		</div><!-- button -->
  
 <div class="button">
<a href="teacher.html">Teacher</a>
</div><!-- button -->

	</section><!-- content -->
</div><!-- container -->
</body>
    
        <script src="js/index.js"></script>

  </body>
</html>



What I have tried:

i want to login from test database table student by using above html code

解决方案

I don't know if you are simply trying to connect to mysql via php or if you are trying to create login functionality via mysql.

1) If you are trying to create login functionality you can either roll this code yourself or find an existing framework to do this for you.

Essentially you need to pass the username/password to your server side code (looks like login.php) and then encrypt/hash the password (assuming you are hashing your passwords) in order to compare it to the password in the database.

In the event you are not hashing, then decrypt your password from the database and make a comparison of what is typed to what exists in the database. If it matches, great, user is authenticated. If not, then display an error message.

Given that I have no other knowledge about your code I can't even begin to provide code samples or anything else. What you are doing has been done thousands of times before you and isn't new. You should use google to find sample login php code and adapt that to your needs. Break your issue into smaller pieces and begin to implement what it is you need. Trying to find a one size fits all solution on the internet to your specific problem can be something highly unlikely to find.

You should attempt creating the code yourself and if you have issues come back with better code samples rather than just showing html, which has very little to do with what you are trying to accomplish, and a clearly defined explanation of your issue you are having.

2) So how to connect to mysql using php

Google[^]

PHP Connect to MySQL[^]

PHP: mysql_connect - Manual[^]


这篇关于我如何使用此HTML代码在PHP中连接并登录mysql localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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