• php mysql增、删、改、查


    <?php
    	require_once "connect.php";
    echo <<<_END
    <!DOCTYPE HTML>
    <html dir="ltr" lang="zh-CN">
    	<head>
    		<meta charset="utf-8">
    		<title></title>
    	</head>
    	<body>
    		<form action="sql_test.php" method="post">
    			<fieldset>
    				<legend>ADD DEMO</legend>
    				<p>
    					<label for="name">Name: </label>
    					<input type="text" name="name"/>
    				</p>
    				<p>
    					<label for="age">Age: </label>
    					<input type="text" name="age"/>
    				</p>
    				<p>
    					<label for="sex">Sex: </label>
    					<input type="text" name="sex"/>
    				</p>
    			</fieldset>
    			<fieldset>
    				<input type="submit" name="add_submit" value="提交"/>
    				<input type="reset" value="重置"/>
    			</fieldset>
    		</form>
    	</body>
    </html>
    _END;
    if (isset($_POST["name"]) && isset($_POST["age"]) && isset($_POST["sex"]) && isset($_POST["add_submit"])) {
    	$name=$_POST["name"];
    	$age=$_POST["age"];
    	$sex=$_POST["sex"];
    }
    if(isset($_POST["add_submit"])){
    	mysql_query("set names utf8");
    	$add_query="insert into users(name,age,sex) values('$name','$age','$sex')";
    	mysql_query($add_query);
    }
    mysql_query("set names utf8");
    $select_query="select * from users";
    $results=mysql_query($select_query);
    while ($rows=mysql_fetch_row($results)) {
    	echo "Id:".$rows[0]."<br>";
    	echo "Name:".$rows[1]."<br>";
    	echo "Age:".$rows[2]."<br>";
    	echo "Sex:".$rows[3]."<br>"."<br>"."<br>";
    }
    echo <<<_END
    <form action="sql_test.php" method="post">
    	<fieldset>
    		<legend>DELETE DEMO</legend>
    		<p>
    			<label for="id">ID: </label>
    			<input type="text" name="id"/>
    		</p>
    	</fieldset>
    	<fieldset>
    		<input type="submit" name="del_submit" value="提交"/>
    		<input type="reset" value="重置"/>
    	</fieldset>
    </form>
    _END;
    if(isset($_POST["id"]) && isset($_POST["del_submit"])){
    	$id=$_POST["id"];
    }
    if(isset($_POST["del_submit"])){
    	$del_query="delete from users where id='$id'";
    	mysql_query($del_query);
    }
    
    mysql_query("set names utf8");
    $select_query="select * from users";
    $results=mysql_query($select_query);
    while ($rows=mysql_fetch_row($results)) {
    	echo "Id:".$rows[0]."<a href='sql_test?'>Edit</a>"."<br>";
    	echo "Name:".$rows[1]."<br>";
    	echo "Age:".$rows[2]."<br>";
    	echo "Sex:".$rows[3]."<br>"."<br>"."<br>";
    }
    echo <<<_END
    <form action="sql_test.php" method="post">
    	<fieldset>
    		<legend>UPDATE DEMO</legend>
    		<p>
    			<label for="id">ID: </label>
    			<input type="text" name="id"/>
    		</p>
    		<p>
    			<label for="name">Name: </label>
    			<input type="text" name="name"/>
    		</p>
    		<p>
    			<label for="age">Age: </label>
    			<input type="text" name="age"/>
    		</p>
    		<p>
    			<label for="sex">Sex: </label>
    			<input type="text" name="sex"/>
    		</p>
    	</fieldset>
    	<fieldset>
    		<input type="submit" name="update_submit" value="提交"/>
    		<input type="reset" value="重置"/>
    	</fieldset>
    </form>
    _END;
    if(isset($_POST["name"]) && isset($_POST["age"]) && isset($_POST["sex"]) && isset($_POST["update_submit"])){
    	$name=$_POST["name"];
    	$age=$_POST["age"];
    	$sex=$_POST["sex"];
    	$id=$_POST["id"];
    }
    if(isset($_POST["update_submit"])){
    	$up_query="update users set name='$name',age='$age',sex='$sex' where id='$id'";	
    	mysql_query($up_query);
    }
    mysql_query("set names utf8");
    $select_query="select * from users";
    $results=mysql_query($select_query);
    while ($rows=mysql_fetch_row($results)) {
    	echo "Id:".$rows[0]."<a href='sql_test?'>Edit</a>"."<br>";
    	echo "Name:".$rows[1]."<br>";
    	echo "Age:".$rows[2]."<br>";
    	echo "Sex:".$rows[3]."<br>"."<br>"."<br>";
    }
    echo <<<_END
    <form action="sql_test.php" method="post">
    	<fieldset>
    		<legend>SELECT DEMO</legend>
    		<p>
    			<label for="id">ID: </label>
    			<input type="text" name="id"/>
    		</p>
    		<p>
    			<label for="name">Name: </label>
    			<input type="text" name="name"/>
    		</p>
    		<p>
    			<label for="age">Age: </label>
    			<input type="text" name="age"/>
    		</p>
    		<p>
    			<label for="sex">Sex: </label>
    			<input type="text" name="sex"/>
    		</p>
    	</fieldset>
    	<fieldset>
    		<input type="submit" name="select_submit" value="提交"/>
    		<input type="reset" value="重置"/>
    	</fieldset>
    </form>
    _END;
    if (isset($_POST["select_submit"])) {
    	if(isset($_POST["name"])){
    		$name=$_POST["name"];
    		$sel_results=mysql_query("select * from users where name='$name'");
    		while ($rows=mysql_fetch_row($sel_results)) {
    			echo "id: ".$rows[0]."<br>";
    			echo "name: ".$rows[1]."<br>";
    			echo "age: ".$rows[2]."<br>";
    			echo "sex: ".$rows[3]."<br>"."<br>";
    		}
    	}
    	if (isset($_POST["age"])) {
    		$age=$_POST["age"];
    		$sel_results=mysql_query("select * from users where age='$age'");
    		while ($rows=mysql_fetch_row($sel_results)) {
    			echo "id: ".$rows[0]."<br>";
    			echo "name: ".$rows[1]."<br>";
    			echo "age: ".$rows[2]."<br>";
    			echo "sex: ".$rows[3]."<br>"."<br>";
    		}
    	}
    	if (isset($_POST["sex"])) {
    		$sex=$_POST["sex"];
    		$sel_results=mysql_query("select * from users where sex='$sex'");
    		while ($rows=mysql_fetch_row($sel_results)) {
    			echo "id: ".$rows[0]."<br>";
    			echo "name: ".$rows[1]."<br>";
    			echo "age: ".$rows[2]."<br>";
    			echo "sex: ".$rows[3]."<br>"."<br>";
    		}
    	}
    	if (isset($_POST["id"])) {
    		$id=$_POST["id"];
    		$sel_results=mysql_query("select * from users where id='$id'");
    		while ($rows=mysql_fetch_row($sel_results)) {
    			echo "id: ".$rows[0]."<br>";
    			echo "name: ".$rows[1]."<br>";
    			echo "age: ".$rows[2]."<br>";
    			echo "sex: ".$rows[3]."<br>"."<br>";
    		}
    		# code...
    	}
    }
    ?>
    

      

  • 相关阅读:
    SQL必知必会-笔记(五)函数
    软件测试面试题:系统中的图片不显示如何排查原因
    windows用浏览器访问linux目录文件
    记测试工作中一次印象深刻的事
    怎么快速适应新的测试工作?
    xshell如何导出日志文件和上传文件
    jmeter+fiddler高效率整理接口脚本
    python-用requests库处理form-data格式的参数
    软件自动化测试工程师面试题集锦(4)
    shell脚本批量检查某个或多个服务的端口和进程是否正常
  • 原文地址:https://www.cnblogs.com/wangwenfei/p/mysql.html
Copyright © 2020-2023  润新知