Home > php教程 > php手册 > 添加表单

添加表单

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:39:45
Original
1556 people have browsed it

无详细内容 ?phpheader('Content-Type:text/html;charset=utf-8');$locahost="localhost";$name="root";$password="root";$dbname='test';$con=mysql_connect($locahost,$name,$password,$dbname);if (!$con) { die('链接失败'.mysql_error());}mysql_select

<?php
header('Content-Type:text/html;charset=utf-8');
$locahost="localhost";
$name="root";
$password="root";
$dbname='test';

$con=mysql_connect($locahost,$name,$password,$dbname);
if (!$con) {
        die('链接失败'.mysql_error());
}
mysql_select_db("test",$con);


if (isset($_POST['submit'])) {
    if (empty($_POST['title'])) {
        echo "<script>alert('请输入标题');</script>";
        exit(0);
    }
    if (empty($_POST['count'])) {
        echo "<script>alert('请输入计算');</script>";
        exit(0);
    }

if (strlen($_POST['title'])<2||strlen($_POST['count'])>10) {
    echo "<script>alert('题目2到10之间');</script>";
    return true;
}

// 添加数据
$sql="insert into ji(title,count)values('$_POST[title]','$_POST[count]')";
$reqult=mysql_query($sql);
if (!$reqult) {
    die('Error:'.mysql_error());
 }
echo "添加成功";
mysql_close($con);
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="jifen.php" method="post">
    
    标题:<input type="text" name="title">
    计算:<input type="text" name="count">
    <input type="submit" name="submit">
    </form>
</body>
</html>
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template