PHP学习笔记2——前后端,mysql增删改查

php是一种适用于后端与前端的编程语言

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>index</title>
    <style>
.denglu{

    position: fixed;
    bottom: 50%;
    left: 45%;
}
    </style>
</head>
<body background="./t012bbe9039d3179317.jpg">
  <div class="denglu"> <form action="./index.php" method="get">
    money <input type="number" name="money">
    <button type="submit">提交</button>
    <br>
    name <input type="text" name="namel">
    <button type="submit">提交</button>



   </form></div>

</body>
</html>
<?php

$q=$_GET['money'];
$p=$_GET['namel'];
session_start();
$_SESSION["name"]=$p;
echo "<script>alert('点击确定,返回上一页面');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
if($_SESSION["name"]=="zzzk"){
    echo "welcome";
}else{
    echo "do not have $p";
}

?>

这里在html文件中创建了一个表单,并且通过get,将表单上传到php文件中进行处理,其中form中的参数action提供接口作用,这里前后端衔接的关键在于前端数据通过name传递,后端通过$_GET["name名"]得到前端传递来的值

 

 

对传递来的数据,我们可以通过mysql进行基本的操作,其中mysql常用语句有

INSERT INTO user(user的字段) VALUES(要给字段添加的值)给user表添加一个新的值

DELETE FROM user WHERE uid=1 删除uid为1的user字段

UPDATA user SET username=“新的值” WHERE uid=1 给uid为1的字段更新username值

SELECT 要查找内容 FROM 要查找范围

 

 

 

  • 20
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 Android 笔记本应用的代码示例,包括增加、删除、修改和查找笔记的功能: 1. 在 activity_main.xml 中添加一个 ListView 元素和三个 Button 元素,以便用户列出、添加、编辑和删除笔记: ```xml <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/addButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Add"/> <Button android:id="@+id/editButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Edit"/> <Button android:id="@+id/deleteButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Delete"/> ``` 2. 在 note_item.xml 中添加一个 TextView 元素,以便在 ListView 中显示笔记的标题: ```xml <TextView android:id="@+id/titleTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:padding="10dp"/> ``` 3. 在 MainActivity.java 文件中编写以下代码: ```java import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { ListView listView; Button addButton, editButton, deleteButton; ArrayList<String> notes; ArrayAdapter<String> adapter; int selectedIndex = -1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = findViewById(R.id.listView); addButton = findViewById(R.id.addButton); editButton = findViewById(R.id.editButton); deleteButton = findViewById(R.id.deleteButton); notes = new ArrayList<>(); adapter = new ArrayAdapter<>(this, R.layout.note_item, R.id.titleTextView, notes); listView.setAdapter(adapter); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showNoteDialog("New note", "", true); } }); editButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (selectedIndex != -1) { String note = notes.get(selectedIndex); showNoteDialog("Edit note", note, false); } else { Toast.makeText(MainActivity.this, "Please select a note to edit", Toast.LENGTH_SHORT).show(); } } }); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (selectedIndex != -1) { String note = notes.get(selectedIndex); showDeleteDialog(note); } else { Toast.makeText(MainActivity.this, "Please select a note to delete", Toast.LENGTH_SHORT).show(); } } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { selectedIndex = i; } }); } private void showNoteDialog(String title, String note, final boolean isNew) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(title); final EditText input = new EditText(this); input.setText(note); builder.setView(input); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { String text = input.getText().toString(); if (isNew) { notes.add(text); } else { notes.set(selectedIndex, text); } adapter.notifyDataSetChanged(); } }); builder.setNegativeButton("Cancel", null); builder.show(); } private void showDeleteDialog(final String note) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Delete note"); builder.setMessage("Are you sure you want to delete this note?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { notes.remove(note); adapter.notifyDataSetChanged(); selectedIndex = -1; } }); builder.setNegativeButton("No", null); builder.show(); } } ``` 4. 运行应用程序并测试添加、编辑、删除和查找笔记的功能。 注意:这只是一个简单的笔记本应用程序示例,未进行任何输入验证或错误处理。在实际应用程序中,您可能需要添加更多的代码来确保应用程序的稳定性和安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值