用户登录填充Txtbox W / DataBase数据,UPDATE +使用帐户类型如何拥有 [英] user Login populate Txtbox W/DataBase data, UPDATE + use account types how to have

查看:85
本文介绍了用户登录填充Txtbox W / DataBase数据,UPDATE +使用帐户类型如何拥有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我目前用我的简单表格成功建立了一个关系数据库。

现在我正在努力让我的简单网站有两种不同类型的登录用户,例如管理员和常规用户帐户。我希望能够为帐户拥有不同的权限。我可以成功登录帐户,但我不太确定如何使用登录做任何事情。现在我只回应一个声明,说该帐户已登录。

我想知道如何从数据库中提取用户数据并填充文本框中的数据以填充它们然后我' d喜欢能够做一个UPDATE语句

我是否使用$ _SESSION或$ _COOKIE?使用登录我一直试图在谷歌搜索它,以了解如何使用登录帐户做一些事情,但我还没有能够解决任何问题... ..

我想要我的帐户如果有人有时间向我展示如何管理帐户,然后使用管理员创建其他用户,那么能够更新那里的信息会很酷,但我只是想让事情的基本过程先行。当用户登录时,我想将它们发送到表单页面并让它自动填充当前信息的文本框,然后如果他们更改它并单击提交运行更新查询,以便更新数据库。

有人可以帮我这个吗?

以下是我所拥有的大部分内容,因此您可以看到如何在接下来的步骤中进一步推动我。



Hello all,
I currently successfully made a relational database with my simple form.
Now I am working on having my simple website have a login with 2 different types of users, for example like an administrator and a regular user account. I would like to be able to have different privileges for the accounts. I can successfully log an account in but I am not quite sure how to do anything with the login. Right now I only echo a statement saying that the account has logged in.
I would like to know how to pull user data from the database and fill the textboxes with the data to populate them and then I’d like to be able to do an UPDATE statement
Do I use a $_SESSION or $_COOKIE ? to use the login I been trying to search it on Google to learn how to do something with a logged in account but I have not been able to figure anything out yet…..
I would like my accounts to be able to update there information if someone has time to show me how to do an admin account then creating additional users with an admin would be cool but I just simply want the basic process of stuff working first. When a user logins I want to send them to the form page and have it auto populate the textboxes with there current information then if they change it and click submit run a update query so it updates the database.
Could someone please help me with this?
Here is most of what I have so you can see how to push me further in the next steps.

<div id="section1"> 			
  			<?php
  				if(!isset($_POST['btnSubmit']))
				{
			?>	
					<form method="post" action="index.php">
						<label for="username">Username:</label>
						<input type="text" name="username" />
						<br>
						<label for="password">Password:</label>
						<input type="text" name="password" />
						<br>
						<input type="submit" name="btnSubmit" value="Log In!" />
					</form>
			<?php
			//the form is submitted check everything to login successfully
				}
				else 
				{		//get user input and store in variables
					$username = $_POST['username'];
					$password = $_POST['password'];
					
				  	if (empty($username)) 
			      	{
			        	die('ERROR: Please enter your username');  
			      	}
			      	if (empty($password)) 
			      	{
			        	die('ERROR: Please enter your password');  
			      	}

					$mysqli = new mysqli("localhost", "root", "", "loginusers");
					//xampp
					if ($mysqli === false) 
				    {
				      die("ERROR: Could not connect to database. " . mysqli_connect_error());
				    }
				    
					//take user input and make sure there are no "/"s in it 
					$username = $mysqli->escape_string($username);
				    
					 $sql = "SELECT COUNT(*) FROM users WHERE username = '$username'";
				      if ($result = $mysqli->query($sql)) 
				      {
				        $row = $result->fetch_array();
				        // if yes, fetch the encrypted password
				        if ($row[0] == 1) 
				        {
				          $sql = "SELECT password FROM users WHERE username = '$username'"; 
						         
				          if ($result = $mysqli->query($sql)) 
				          {
				            $row = $result->fetch_object();    
				
				            $hash = $row->password;
							
							
							if (crypt($password, $hash) == $hash) 
				            {              
				              echo 'Your login credentials were successfully verified.';  
				            } 
				            else 
				            {
				              echo 'You entered an incorrect password.';            
				            }
				          } 
						  else 
				          {
				            echo "ERROR: Could not execute $sql. " . $mysqli->error;
				          }          
				        } 
				        else 
				        {
				          echo 'You entered an incorrect username.';            
				        }
				
				        $result->close();
				      } 
				      else 
				      {
				        echo "ERROR: Could not execute $sql. " .$mysqli->error;
				   
				      }
					  
					  $mysqli->close();
				}
			?>
  			
  	</div>

推荐答案

_SESSION或


_COOKIE?使用登录我一直试图在谷歌搜索它,以了解如何使用登录帐户做一些事情,但我还没有能够解决任何问题... ..

我想要我的帐户如果有人有时间向我展示如何管理帐户,然后使用管理员创建其他用户,那么能够更新那里的信息会很酷,但我只是想让事情的基本过程先行。当用户登录时,我想将它们发送到表单页面并让它自动填充当前信息的文本框,然后如果他们更改它并单击提交运行更新查询,以便更新数据库。

有人可以帮我这个吗?

以下是我所拥有的大部分内容,因此您可以看到如何在接下来的步骤中进一步推动我。



_COOKIE ? to use the login I been trying to search it on Google to learn how to do something with a logged in account but I have not been able to figure anything out yet…..
I would like my accounts to be able to update there information if someone has time to show me how to do an admin account then creating additional users with an admin would be cool but I just simply want the basic process of stuff working first. When a user logins I want to send them to the form page and have it auto populate the textboxes with there current information then if they change it and click submit run a update query so it updates the database.
Could someone please help me with this?
Here is most of what I have so you can see how to push me further in the next steps.

<div id="section1"> 			
  			<?php
  				if(!isset(


_POST [' btnSubmit']))
{
?>
< 表格 方法 = post action = index.php >
< label = 用户名 > 用户名:< / label >
< 输入 < span class =code-attribute>
type = text name = 用户名 / >
< br >
< label for = 密码 > 密码:< ; / label >
< 输入 type = text name = password / >
< br >
< 输入 类型 = 提交 name = btnSubmit value = 登录! / >
< /表格 >
<? php
// 表单已提交,检查所有内容是否成功登录
}
else
{ // 获取用户输入并存储在变量中
_POST['btnSubmit'])) { ?> <form method="post" action="index.php"> <label for="username">Username:</label> <input type="text" name="username" /> <br> <label for="password">Password:</label> <input type="text" name="password" /> <br> <input type="submit" name="btnSubmit" value="Log In!" /> </form> <?php //the form is submitted check everything to login successfully } else { //get user input and store in variables


这篇关于用户登录填充Txtbox W / DataBase数据,UPDATE +使用帐户类型如何拥有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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