• php使用select语句查询数据信息


    <html>
    <head>
       <title>Finding User</title>
    </head>
    <body>
      <h2>Finding users from mysql database.</h2>
      <form action="selectformhandler.php" method="post">
         Select gender:
    	 <select name="gender">
    	   <option value="male">man</option>
    	   <option value="female">woman</option>
    	 </select><br />	 
    	 <input name="submit" type="submit" value="Find"/>
      </form>
    </body>
    </html>
    

      

    <html>
    <head>
       <title>User found</title>
    </head>
    <body>
       <h2>User found from mysql database.</h2>
    <?php
    	$gender = $_POST['gender'];
    	if(!$gender){
    	    echo "Error: There is no data passed.";
    		exit;
    	}
    	if(!get_magic_quotes_gpc()){
    		$gender = addslashes($gender);
    	}
    		@ $db = mysqli_connect('localhost','root','12345678');
    		mysqli_select_db($db,'testphp');
    		if(mysqli_connect_errno()){
    	 	 echo "Error: Could not connect to mysql database.";
    	 	 exit;
    		}
    		$q = "SELECT * FROM user WHERE gender = '".$gender."'";
    		$result = mysqli_query($db,$q);
    		$rownum = mysqli_num_rows($result);
    		for($i=0; $i<$rownum; $i++){
    		   $row = mysqli_fetch_assoc($result);
    		   echo "Id:".$row['id']."<br />";
    		   echo "Name:".$row['name']."<br />";
    		   echo "Age:".$row['age']."<br />";
    		   echo "Gender:".$row['gender']."<br />";
    		   echo "Info:".$row['info']."<br />";
    		}
    		mysqli_free_result($result);
    		mysqli_close($db);
    ?>
    </body>
    </html>
    

      

  • 相关阅读:
    AES算法,DES算法,RSA算法JAVA实现
    spring官方学习地址
    逐步理解SpringMVC
    sublime前端开发工具常用技巧
    谈谈关键字new
    关于mybatisgenerator的问题
    AOPjdk动态代理的思考
    关于java解析xml文件出现的问题
    Java注解
    git向码云上传代码总结
  • 原文地址:https://www.cnblogs.com/DamonBlog/p/10121112.html
Copyright © 2020-2023  润新知