search
HomeBackend DevelopmentPHP TutorialHow 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 developmentcustomer relationship management systemSimple

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);
?>
  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>
  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>

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
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)