mysql add attr mysql增刪改處理

2021-10-17 21:35:46 字數 2612 閱讀 6727

首頁:

代號姓名

性別民族

生日 $db = new mysqli ("localhost","root","","mydb");

!mysqli_connect_error() or die ("連線失敗!");

$sql = "select * from info";

$result = $db->query($sql);

if($result)

$attr = $result->fetch_all();

foreach ($attr as $a)

$*** = $a[2]?"男":"女";

$sql1 = "select name from nation where code=''";

$re1 = $db->query($sql1);

$attr1 = $re1->fetch_assoc();

echo "

刪除修改";

新增資料

新增資料:

代號:

姓名:

性別: 男

女 民族:

$db = new mysqli("localhost","root","","mydb");

$sql = "select * from nation";

$r = $db->query($sql);

$attr = $r->fetch_all();

foreach($attr as $v)

echo "";

生日:主頁面

增加處理:

$code = $_post["code"];

$name = $_post["name"];

$*** = $_post["***"];

$s = 1;

if($***=="女")

$s=0;

$nation = $_post["nation"];

$birthday = $_post["birthday"];

$db = new mysqli("localhost","root","","mydb");

!mysqli_connect_error() or die("連線失敗!");

$c="insert into info values('','',,'','')";

$r = $db->query($c);

if($r)

header("location:add.php");

else

echo "新增失敗!";

修改:h1>修改資料

$code1 = $_get["code"];

$db = new mysqli("localhost","root","","mydb");

!mysqli_connect_error() or die ("連線失敗!");

$sql = "select * from info where code=''";

$r = $db->query($sql);

$attr = $r->fetch_row();

姓名:

性別: />男

/>女

民族:$sql1 = "select * from nation";

$r1 = $db->query($sql1);

$attr1 = $r1->fetch_all();

foreach($attr1 as $v)

if($v[0]==$attr[3])

echo "";

else

echo "";

生日:主頁面

修改處理:

$code = $_post["code"];

$name = $_post["name"];

$*** = $_post["***"];

$s = 1;

if($***=="女")

$s=0;

$nation = $_post["nation"];

$birthday = $_post["birthday"];

$db = new mysqli("localhost","root","","mydb");

!mysqli_connect_error() or die("連線失敗!");

$c="update info set name='',***='',nation='',birthday='' where code=''";

$r = $db->query($c);

if($r)

header("location:updeat.php");

else

echo "修改失敗!";

刪除:$code = $_get["code"];

$db = new mysqli("localhost","root","","mydb");

!mysqli_connect_error() or die("連線失敗!");

$sql = "delete from info where code =''";

$r = $db->query($sql);

if($r)

header("location:sy.php.php");

else

echo "刪除失敗!";

mysql增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...

mysql增刪改查擴充套件 MySQL增刪改查

1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...

增刪改查 JS陣列增刪改查這點事兒

1 length屬性 length屬性是陣列最重要的屬性,沒有之一,length屬性告訴我們這個陣列內有多少個資料元素,當length 0時說明陣列時乙個空陣列。我們想要遍歷陣列時可以直接將遍歷的終點設為 length 1。這是本文的重點,我們從增刪改查方面入手,梳理方法的作用和用法,有利於記憶和使...