Simple Management System (PHP) based on MySQL

Original Link: https://my.oschina.net/gal/blog/200190

Environment: Because it's not real server building, I'm lazy about phpstudy, integrating lightweight apache,mysql and php. IDE with Eclipse PHP Studio, after all, I'm used to Eclipse.

 

Set apache native directory (same as EPS project directory), add test database fansdb using phpMyAdmin, and create a new table test (with two fields: user and password)

 

 

 

 

Source for each page:

//index.php

Background management logon: <br>
<form action="login.php" method="post">
	Name: <input type="text" name="name"/> 
	Password: <input type="text" name="password"/>
	<input type="submit" name="submit" value="submit"/>
</form>


 

//login.php

<?php
require_once 'connectdb.php';
$name = $_POST['name'];
$passowrd = $_POST['password'];
$passowrd = md5($passowrd);

if ($name && $passowrd){
	$sql = "SELECT * FROM test WHERE user = '$name' and password='$passowrd'";
	$res = mysql_query($sql);
	$rs=mysql_num_rows($res);
	if($rs){
		header("refresh:0;url=userui.php");
		exit;
	}
	else
		echo "<script language=javascript>alert('User name password error');history.back();</script>";
}else {
	echo "<script language=javascript>alert('User name password cannot be empty');history.back();</script>";
}
?>


 

//userui.php

<form action="" method="post">
<input type="submit" name="btn" value="List all"/>
<input type="submit" name="btn" value="increase"/>
<input type="submit" name="btn" value="delete"/>
<input type="submit" name="btn" value="modify"/>
<input type="submit" name="btn" value="lookup"/>
</form>

<?php
require_once 'controldb.php';
$action = $HTTP_POST_VARS["btn"];

switch($action){
	case "List all":
		listuser();
		break;
	case "increase":
		echo "<form action=\"\" method=\"post\">
		//Name: <input type=\"text\" name=\"name\"/>
		//Password: <input type=\"text\" name=\"password\"/>
		<input type=\"submit\" name=\"btn\" value=\"Determine Add\"/>
		<br>";
		break;
	case "delete":
		echo "<form action=\"\" method=\"post\">
		//Find Name: <input type=\"text\" name=\"name\"/>
		<input type=\"submit\" name=\"btn\" value=\"Determine Delete\"/>
		<br>";
		break;
	case "modify":
		echo "<form action=\"\" method=\"post\">
		//Find Name: <input type=\"text\" name=\"name\"/>
		//Modified name: <input type=\"text\" name=\"dest_name\"/>
		//Modified password: <input type=\"text\" name=\"dest_password\"/>
		<input type=\"submit\" name=\"btn\" value=\"Determine modifications\"/>
		<br>";
		break;
	case "lookup":
		echo "<form action=\"\" method=\"post\">
		//Find Name: <input type=\"text\" name=\"name\"/>
		<input type=\"submit\" name=\"btn\" value=\"Determine Find\"/>
		<br>";
		break;
		
	case "Determine Add":
		if(add($_POST['name'],$_POST['password']))
			echo "Added Successfully";
		else
			echo "Failed to add";
		break;
	case "Determine Delete":
		if(del($_POST['name']))
			echo "Delete succeeded";
		else
			echo "Delete failed,This person may not exist";
		break;
	case "Determine modifications":
		if(change($_POST['name'],$_POST['dest_name'],$_POST['dest_password']))
			echo "Successful modification";
		else
			echo "Modification failed,This person may not exist";
		break;
	case "Determine Find":
		$rs = search($_POST['name']);
		if($rs)
			echo "User name:".$rs->user."<br>User Password(after md5):".$rs->password;
		else
			echo "Search failed,This person may not exist";
		break;
		
}

?>


 

//conectdb.php

<?php
$mysql_servername = "localhost"; //Host Address
$mysql_username = "root"; //Database User Name
$mysql_password ="root"; //Database Password
$mysql_database ="fansdb"; //data base
mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database); 
?>


 

//controldb.php

<?php
require_once 'connectdb.php';
function add($name,$password){
	$password = md5($password);
	$sql = "INSERT INTO test(user, password) VALUE('$name', '$password')";
	$rlt = mysql_query($sql);
	return $rlt;
}

function del($name){
	$sql = "DELETE FROM test WHERE user='$name'";
	$rlt = mysql_query($sql);
	return $rlt;
}

function change($name,$dest_name,$dest_password){
	$dest_password = md5($dest_password);
	$sql = "UPDATE test SET user='$dest_name',password='$dest_password' WHERE user = '$name'";
	$rlt = mysql_query($sql);
	return $rlt;
}

function search($name){
	$sql = "SELECT * FROM test WHERE user='$name'";
	$rlt = mysql_query($sql);
	$rs=mysql_fetch_object($rlt);
	return $rs;
}

function listuser(){
	$sql="SELECT * FROM test"; 
	$rlt=mysql_query($sql);
	while($rs=mysql_fetch_object($rlt)) {
		echo "User name:".$rs->user."<br>User Password(after md5):".$rs->password."<br>";
  }
}

?>

 

Landing page:

 

Action Page:

 

Note: Manually add an item with a password and user name of root to the database using the add function at a debug time.

 

Summary: In fact, this topic is not too difficult, mainly to study sql language? Basically the first time I came into contact with web development, I didn't know anything about html at all, so the ui side is the same bird. As for all kinds of irregularities and laziness in the code, that's the same. PHP was born for the web, I still play with my lua more intimate.In weak types, but lua is much safer. Probably. The system global variables in PHP should all be pseudo arrays based on hash tables? Each post action will put name,value equal push in a static web page and use it to interact with php? Mark it up and have time later, or be interested in learning about web and php.

 

As for the innovation class, it may make sense to leave no comment on it for the moment. But the time is so fixed that I put all my time on the web and give up what I am interested in. In a word, this is also the case.

Reprinted at: https://my.oschina.net/gal/blog/200190

Tags: PHP SQL Database Apache

Posted on Thu, 12 Sep 2019 11:32:31 -0700 by Loldongs