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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function