Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_host = 'localhost';
- $db_database = 'btlse2010';
- $db_username = 'binh';
- $db_password = '';
- if ($_POST["submit"] == "Submit"){
- // Connect
- $connection = mysql_connect($db_host, "root", "");
- if (!$connection){
- die ("Could not connect the databases : <br />".mysql_error());
- }
- // Select the database
- $db_select=mysql_select_db($db_database);
- if (!$db_select){
- die("Could not select the database: <br />".mysql_error());
- }
- // Assign the query
- $query = "SELECT * FROM `students`";
- // Execute the query
- $result=mysql_query($query);
- if (!$result){
- die ("Could not query the database: <br />".mysql_error());
- }
- $mssv = $_POST["mssv"];
- $pass = $_POST["pass"];
- $name = $_POST["name"];
- $birthday = $_POST["birthday"];
- // Insert value to database
- mysql_query ("INSERT INTO students (mssv, password, full_name, birthday)
- VALUES('$mssv', '$pass', '$name', '$birthday')");
- }
- $choice = $_GET["choice"];
- if (!empty($choice)){
- foreach ($_GET[choice] as $stu){
- // Add a new student to the dababase
- if ($stu == "add"){
- echo "<strong>NHAP THONG TIN SINH VIEN </strong>";
- echo ('<form action="'.$_SERVER["PHP_SELF"].'" method="POST">
- <fieldset>
- <label>Ma so sinh vien: <input type="varchar" name="mssv" value="" <br /></label>
- <label>Password: <input type="varchar" name="pass" value="" <br /> </label>
- <label>Ho va ten: <input type="varchar" name="name" value="" <br /> </label>
- <label>Ngay sinh: <input type="date" name="birthday" value="" <br /></label>
- </fieldset>
- <input type="submit" value="Submit" />
- ');
- }
- // Remove a student in the database
- else{
- echo "<strong>NHAP MA SO SINH VIEN CAN XOA</strong> <br /><br />";
- echo ('<form>
- <label>Ma so sinh vien: <input type="varchar" name="mssv" value="" <br /></label>
- <input type="submit" value="Submit" />
- ');
- }
- }
- }
- // Choice
- else{
- echo ('<form action="'.$_SERVER["PHP_SELF"].'" method="GET">
- <fieldset>
- <label>
- Add a student <input type="radio", name="choice[]", value="add" />
- </label>
- <label>
- Remove a student <input type="radio", name="choice[]", value="remove" />
- </label>
- </fieldset>
- <input type="submit" value="Ok!" />');
- echo "$choice <br />";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement