Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host="localhost"; //replace with database hostname
- $username="username"; //replace with database username
- $password="password"; //replace with database password
- $db_name="db_name"; //replace with database name
- $con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- if($_SERVER["REQUEST_METHOD"] == "POST") {
- $matric = $_POST['matric'];
- $sql = "select * from students where `matric` = '$matric'";
- } else {
- $sql = "select * from students";
- }
- $result = mysql_query($sql);
- $json = array();
- if(mysql_num_rows($result)){
- while($row=mysql_fetch_assoc($result)){
- $json['stu_info'][]=$row;
- }
- }
- mysql_close($con);
- echo json_encode($json);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement