SHARE
TWEET

Untitled

a guest Jun 18th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $db_host = 'localhost';
  4.  
  5. $db_database = 'btlse2010';
  6.  
  7. $db_username = 'binh';
  8.  
  9. $db_password = '';
  10.  
  11.  
  12. if ($_POST["submit"] == "Submit"){
  13.     // Connect
  14.  
  15.     $connection = mysql_connect($db_host, "root", "");
  16.  
  17.     if (!$connection){
  18.  
  19.         die ("Could not connect the databases : <br />".mysql_error());
  20.  
  21.     }
  22.  
  23.  
  24.  
  25.     // Select the database
  26.  
  27.     $db_select=mysql_select_db($db_database);
  28.  
  29.     if (!$db_select){
  30.  
  31.         die("Could not select the database: <br />".mysql_error());
  32.  
  33.     }
  34.  
  35.  
  36.  
  37.  
  38.     // Assign the query
  39.  
  40.     $query = "SELECT * FROM `students`";
  41.  
  42.     // Execute the query
  43.  
  44.     $result=mysql_query($query);
  45.  
  46.     if (!$result){
  47.  
  48.         die ("Could not query the database: <br />".mysql_error());
  49.  
  50.     }
  51.  
  52.  
  53.  
  54.     $mssv = $_POST["mssv"];
  55.  
  56.     $pass = $_POST["pass"];
  57.  
  58.     $name = $_POST["name"];
  59.  
  60.     $birthday = $_POST["birthday"];
  61.  
  62.  
  63.  
  64.     // Insert value to database
  65.  
  66.     mysql_query ("INSERT INTO students (mssv, password, full_name, birthday)
  67.  
  68.             VALUES('$mssv', '$pass', '$name', '$birthday')");
  69. }
  70.  
  71.  
  72. $choice = $_GET["choice"];
  73.  
  74. if (!empty($choice)){
  75.  
  76.     foreach ($_GET[choice] as $stu){
  77.  
  78.         // Add a new student to the dababase
  79.  
  80.         if ($stu == "add"){
  81.  
  82.  
  83.  
  84.             echo "<strong>NHAP THONG TIN SINH VIEN </strong>";
  85.  
  86.             echo ('<form action="'.$_SERVER["PHP_SELF"].'" method="POST">
  87.  
  88.             <fieldset>
  89.  
  90.             <label>Ma so sinh vien: <input type="varchar" name="mssv" value="" <br /></label>
  91.  
  92.             <label>Password: <input type="varchar" name="pass" value="" <br /> </label>
  93.  
  94.             <label>Ho va ten: <input type="varchar" name="name" value="" <br /> </label>
  95.  
  96.             <label>Ngay sinh: <input type="date" name="birthday" value="" <br /></label>
  97.  
  98.             </fieldset>
  99.  
  100.             <input type="submit" value="Submit" />
  101.  
  102.             ');
  103.  
  104.         }
  105.  
  106.         // Remove a student in the database
  107.  
  108.         else{
  109.  
  110.             echo "<strong>NHAP MA SO SINH VIEN CAN XOA</strong> <br /><br />";
  111.  
  112.             echo ('<form>
  113.  
  114.             <label>Ma so sinh vien: <input type="varchar" name="mssv" value="" <br /></label>  
  115.  
  116.             <input type="submit" value="Submit" />
  117.  
  118.             ');
  119.  
  120.         }
  121.  
  122.     }
  123.  
  124. }
  125.  
  126. // Choice
  127.  
  128. else{
  129.  
  130. echo ('<form action="'.$_SERVER["PHP_SELF"].'" method="GET">
  131.  
  132.     <fieldset>
  133.  
  134.         <label>
  135.  
  136.             Add a student <input type="radio", name="choice[]", value="add" />
  137.  
  138.         </label>
  139.  
  140.         <label>
  141.  
  142.             Remove a student <input type="radio", name="choice[]", value="remove" />
  143.  
  144.         </label>
  145.  
  146.     </fieldset>
  147.  
  148.     <input type="submit" value="Ok!" />');
  149.  
  150.     echo "$choice <br />";
  151.  
  152. }
  153.  
  154. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top