Table of Contents
客户列表
添加客户
编辑客户
Home Backend Development PHP Tutorial How to develop a simple customer relationship management system using PHP

How to develop a simple customer relationship management system using PHP

Sep 28, 2023 pm 06:07 PM
php development customer relationship management system Simple

How to develop a simple customer relationship management system using PHP

How to use PHP to develop a simple customer relationship management system

With the development of the Internet and the expansion of enterprise scale, customer relationship management systems (CRM) have become increasingly important in enterprise management. are becoming increasingly important. It can help companies better manage customer information, track sales opportunities, improve customer satisfaction, etc. This article will introduce how to use PHP to develop a simple customer relationship management system to help companies better manage customer relationships.

1. Set up a development environment

First, we need to set up a PHP development environment. It is recommended to use integrated development environments such as XAMPP or WAMP, which can provide an integrated Apache server, MySQL database and PHP environment.
After the installation is complete, start the Apache and MySQL services, and enter localhost in the browser to confirm whether the installation is successful.

2. Create a database

Next, we need to create a database to store customer information. Create a database named "crm" using phpMyAdmin or the MySQL command line.
The following is the SQL code to create the "customers" table:

CREATE TABLE customers (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
phone VARCHAR(15) NOT NULL,
address VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);

三, Create PHP script

  1. Create an "index.php" file to display the customer list and action buttons. The code is as follows:
<?php
// 数据库连接信息
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "crm";

// 连接数据库
$conn = mysqli_connect($hostname, $username, $password, $dbname);

// 检查连接是否成功
if (!$conn) {
  die("连接数据库失败: " . mysqli_connect_error());
}

// 查询所有客户信息
$sql = "SELECT * FROM customers";
$result = mysqli_query($conn, $sql);

// 显示客户信息
echo "<h1 id="客户列表">客户列表</h1>";
echo "<table>";
echo "<tr><th>姓名</th><th>邮箱</th><th>电话</th><th>地址</th><th>操作</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
  echo "<tr>";
  echo "<td>".$row['name']."</td>";
  echo "<td>".$row['email']."</td>";
  echo "<td>".$row['phone']."</td>";
  echo "<td>".$row['address']."</td>";
  echo "<td><a href='edit.php?id=".$row['id']."'>编辑</a> <a href='delete.php?id=".$row['id']."'>删除</a></td>";
  echo "</tr>";
}
echo "</table>";

// 关闭数据库连接
mysqli_close($conn);
?>
Copy after login
  1. Create an "add.php" file to add customer information. The code is as follows:
<?php
// 数据库连接信息
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "crm";

// 连接数据库
$conn = mysqli_connect($hostname, $username, $password, $dbname);

// 检查连接是否成功
if (!$conn) {
  die("连接数据库失败: " . mysqli_connect_error());
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // 获取表单提交的数据
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $address = $_POST['address'];

  // 插入客户信息
  $sql = "INSERT INTO customers (name, email, phone, address) VALUES ('$name', '$email', '$phone', '$address')";
  
  if (mysqli_query($conn, $sql)) {
    echo "添加客户成功";
  } else {
    echo "添加客户失败: " . mysqli_error($conn);
  }
}

// 关闭数据库连接
mysqli_close($conn);
?>

<h1 id="添加客户">添加客户</h1>
<form action="add.php" method="post">
  <label for="name">姓名:</label>
  <input type="text" name="name" required><br>

  <label for="email">邮箱:</label>
  <input type="email" name="email" required><br>

  <label for="phone">电话:</label>
  <input type="text" name="phone" required><br>

  <label for="address">地址:</label>
  <textarea name="address" required></textarea><br>

  <input type="submit" value="添加客户">
</form>
Copy after login
  1. Create an "edit.php" file for editing customer information. The code is as follows:
<?php
// 数据库连接信息
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "crm";

// 连接数据库
$conn = mysqli_connect($hostname, $username, $password, $dbname);

// 检查连接是否成功
if (!$conn) {
  die("连接数据库失败: " . mysqli_connect_error());
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // 获取表单提交的数据
  $id = $_POST['id'];
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $address = $_POST['address'];

  // 更新客户信息
  $sql = "UPDATE customers SET name='$name', email='$email', phone='$phone', address='$address' WHERE id=$id";
  
  if (mysqli_query($conn, $sql)) {
    echo "编辑客户成功";
  } else {
    echo "编辑客户失败: " . mysqli_error($conn);
  }
} else {
  // 获取要编辑的客户信息
  $id = $_GET['id'];
  $sql = "SELECT * FROM customers WHERE id=$id";
  $result = mysqli_query($conn, $sql);
  $customer = mysqli_fetch_assoc($result);
}

// 关闭数据库连接
mysqli_close($conn);
?>

<h1 id="编辑客户">编辑客户</h1>
<form action="edit.php" method="post">
  <input type="hidden" name="id" value="<?php echo $customer['id']; ?>">

  <label for="name">姓名:</label>
  <input type="text" name="name" value="<?php echo $customer['name']; ?>" required><br>

  <label for="email">邮箱:</label>
  <input type="email" name="email" value="<?php echo $customer['email']; ?>" required><br>

  <label for="phone">电话:</label>
  <input type="text" name="phone" value="<?php echo $customer['phone']; ?>" required><br>

  <label for="address">地址:</label>
  <textarea name="address" required><?php echo $customer['address']; ?></textarea><br>

  <input type="submit" value="保存">
</form>
Copy after login

4. Run the program

Place the file created above in the website root directory of the server, and then access localhost/index.php in the browser, that is You can see the customer list page. Click the "Add Customer" button to jump to the add customer page. After filling in the information, click "Add User" to add a customer.
Click the "Edit" button in the customer list to jump to the editing page. After modifying the customer information, click "Save" to save the changes.

Through the above steps, you have successfully developed a simple customer relationship management system using PHP. You can expand and optimize the functions according to your own needs, such as adding search, sorting and other functions to better manage customer relationships.

The above is the detailed content of How to develop a simple customer relationship management system using PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The easiest way to query the hard drive serial number The easiest way to query the hard drive serial number Feb 26, 2024 pm 02:24 PM

The hard disk serial number is an important identifier of the hard disk and is usually used to uniquely identify the hard disk and identify the hardware. In some cases, we may need to query the hard drive serial number, such as when installing an operating system, finding the correct device driver, or performing hard drive repairs. This article will introduce some simple methods to help you check the hard drive serial number. Method 1: Use Windows Command Prompt to open the command prompt. In Windows system, press Win+R keys, enter "cmd" and press Enter key to open the command

How to use Memcache in PHP development? How to use Memcache in PHP development? Nov 07, 2023 pm 12:49 PM

In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

How to write a simple student performance report generator using Java? How to write a simple student performance report generator using Java? Nov 03, 2023 pm 02:57 PM

How to write a simple student performance report generator using Java? Student Performance Report Generator is a tool that helps teachers or educators quickly generate student performance reports. This article will introduce how to use Java to write a simple student performance report generator. First, we need to define the student object and student grade object. The student object contains basic information such as the student's name and student number, while the student score object contains information such as the student's subject scores and average grade. The following is the definition of a simple student object: public

How to write a simple music recommendation system in C++? How to write a simple music recommendation system in C++? Nov 03, 2023 pm 06:45 PM

How to write a simple music recommendation system in C++? Introduction: Music recommendation system is a research hotspot in modern information technology. It can recommend songs to users based on their music preferences and behavioral habits. This article will introduce how to use C++ to write a simple music recommendation system. 1. Collect user data First, we need to collect user music preference data. Users' preferences for different types of music can be obtained through online surveys, questionnaires, etc. Save data in a text file or database

How to write a simple minesweeper game in C++? How to write a simple minesweeper game in C++? Nov 02, 2023 am 11:24 AM

How to write a simple minesweeper game in C++? Minesweeper is a classic puzzle game that requires players to reveal all the blocks according to the known layout of the minefield without stepping on the mines. In this article, we will introduce how to write a simple minesweeper game using C++. First, we need to define a two-dimensional array to represent the map of the Minesweeper game. Each element in the array can be a structure used to store the status of the block, such as whether it is revealed, whether there are mines, etc. In addition, we also need to define

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to implement version control and code collaboration in PHP development? How to implement version control and code collaboration in PHP development? Nov 02, 2023 pm 01:35 PM

How to implement version control and code collaboration in PHP development? With the rapid development of the Internet and the software industry, version control and code collaboration in software development have become increasingly important. Whether you are an independent developer or a team developing, you need an effective version control system to manage code changes and collaborate. In PHP development, there are several commonly used version control systems to choose from, such as Git and SVN. This article will introduce how to use these tools for version control and code collaboration in PHP development. The first step is to choose the one that suits you

How to use PHP to develop the coupon function of the ordering system? How to use PHP to develop the coupon function of the ordering system? Nov 01, 2023 pm 04:41 PM

How to use PHP to develop the coupon function of the ordering system? With the rapid development of modern society, people's life pace is getting faster and faster, and more and more people choose to eat out. The emergence of the ordering system has greatly improved the efficiency and convenience of customers' ordering. As a marketing tool to attract customers, the coupon function is also widely used in various ordering systems. So how to use PHP to develop the coupon function of the ordering system? 1. Database design First, we need to design a database to store coupon-related data. It is recommended to create two tables: one

See all articles