php学生项目,学生管理项目PHP - osc_a5pzxo31的个人空间 - OSCHINA - 中文开源技术交流社区...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:31   1559   0

action.php

#1.连接数据库

try{

$pdo = new PDO("mysql:host=localhost;dbname=php","root","root");

}catch(PDOException $e){

die("数据库连接失败".$e->getMessage());

}

#2.通过aaction的值判断相应的操作

switch($_GET['action'])

{

case 'add'://添加的操作

$name = $_POST['name'];

$age = $_POST['age'];

$sex = $_POST['sex'];

$sql = "insert into test value(null,'{$name}','{$age}','{$sex}')";

$rw = $pdo->exec($sql);

if($rw > 0)

{

echo "";

}

else

{

echo "";

}

break;

case 'del':

$id = $_GET['id'];

$sql = "delete from test where id = {$id}";

$pdo->exec($sql);

header("location:index.php");

break;

case 'edit':

$id = $_POST['id'];

$name = $_POST['name'];

$age = $_POST['age'];

$sex = $_POST['sex'];

$sql = "update test set name = '{$name}',age = {$age},sex = '{$sex}' where id = {$id}";

$res = $pdo->exec($sql);

#echo $res;

if($res > 0)

{

echo "";

}

else

{

echo "";

}

break;

}?>

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP