1字符串分割(看效果)
前:
利用 explode进行字符串分割
代码:
Document
2.年月日对日期的使用
效果如下:
后:
代码如下:
Document
3.字符串str_ireplace使用
效果如下:
前:
后:
源码:
Document
4.数据库连接 数据查询和添加
Document
";
mysqli_query($con, "set names utf8");
$art1 = "";
for ($i = 0; $i < count($_POST['art']); $i++) {
$art1 = $art1 . $_POST['art'][$i] . "";
}
//$sql1="insert into user(name,gender,age,address,art,email) values('小民','男',14,'湖南','qwer','[email protected]')";
$sql1 = "insert into user(name,gender,age,address,art,email) values('" . $_POST['username'] . "','" . $_POST['sex'] . "'," . $_POST['age'] . ",'" . $_POST['dizhi'] . "','" . $art1 . "','" . $_POST['emial'] . "')";
mysqli_query($con, $sql1);
//$list=mysqli_fetch_all($res);
//print_r($list);
$sql = "select * from user";
$res = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($res)) {
echo $row['id'] . "| |" . $row['name'] . "| |" . $row['gender'] . "| |" . $row['age'] . "| |" . $row['address'] . "| |" . $row['art'] . "| |" . $row['email'] . "
";
}
mysqli_close($con);
}
}
?>
5.简单加法计算机
5.数据库数据简单增删改查
代码:
//show.php 展示
编辑||";
echo "删除
";
}
mysqli_close($con);
?>
//update.php 修改
Document
alert('请选择要编辑的信息!'); window.location.href='show.php';";
exit();
}
$sql = "select * from user where id=" . $_GET['no'];
$res = mysqli_query($con, $sql);
if (!$res) {
die("查询错误" . mysqli_error($con));
}
// if(!mysqli_affected_rows($con)){
// echo "";
// exit();
// }
$id;
$name;
$gender;
$age;
$address;
$art = array();
$email;
while ($row = mysqli_fetch_array($res)) {
//echo $row['id']." ".$row['name']." ".$row['gender']." ".$row['age']." ".$row['address']." ".$row['art']." ".$row['email']."|";
$id = $row['id'];
$name = $row['name'];
$gender = $row['gender'];
$age = $row['age'];
$address = $row['address'];
//str_split($row['art'],"-");
$art = explode("-", $row['art']);
//print_r(explode("-",$row['art']));
//$art=$row['art'];
$email = $row['email'];
}
mysqli_close($con);
?>
//update_do.php 修改执行
Document
alert('请从页面选择信息!'); window.location.href='show.php';";
exit();
}
$art1 = "";
for ($i = 0; $i < count($_POST['art']); $i++) {
$art1 = $art1 . "-" . $_POST['art'][$i];
}
$sql = "update user set name='" . $_POST['name'] . "',gender='" . $_POST['gender'] . "',age=" . $_POST['age'] . ",address='" . $_POST['address'] . "',art='" . $art1 . "',email='" . $_POST['email'] . "' where id=" . $_POST['id'] . "";
echo $sql;
$res = mysqli_query($con, $sql);
if (!$res) {
die("修改错误" . mysqli_error($con));
//echo "删除错误".mysqli_error($con);
//exit();
}
if (!mysqli_affected_rows($con)) {
//die("修改出错:".mysqli_error($con));
echo "";
exit();
}
echo "";
mysqli_close($con);
?>
//insert.php 插入
Document
//insert_do.php 插入执行
//header.php 头
显示
插入
//del_do.php 数据删除
alert('请从提交页面选择信息!'); window.location.href='show.php';";
exit();
}
$sql = "delete from user where id=" . $_GET['no'];
$res = mysqli_query($con, $sql);
if (!$res) {
die("删除错误" . mysqli_error($con));
//echo "删除错误".mysqli_error($con);
//exit();
}
if (!mysqli_affected_rows($con)) {
//die("删除出错:".mysqli_error($con));
echo "";
exit();
}
header("location:show.php");
//connect.php 数据库连接