Author: alien

  • Khóa học miễn phí PHP & MySQL – Sorting Data nhận dự án làm có lương

    PHP & MySQL – Sorting Data Example



    PHP uses mysqli query() or mysql_query() function to get sorted records from a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to get sorted records from a table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to get sorted records from a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Sorting MySQL Table records</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             $sql = "SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl order by tutorial_title asc";
             $result = $mysqli->query($sql);
    
             if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                   printf("Id: %s, Title: %s, Author: %s, Date: %d <br />",
                      $row["tutorial_id"],
                      $row["tutorial_title"],
                      $row["tutorial_author"],
                      $row["submission_date"]);
                }
             } else {
                printf(''No record found.<br />'');
             }
             mysqli_free_result($result);
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Id: 5, Title: Apache Tutorial, Author: Suresh, Date: 2021
    Id: 2, Title: HTML Tutorial, Author: Mahesh, Date: 2021
    Id: 1, Title: MySQL Tutorial, Author: Mahesh, Date: 2021
    Id: 3, Title: PHP Tutorial, Author: Mahesh, Date: 2021
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Like Clause nhận dự án làm có lương

    PHP & MySQL – Like Clause Example



    PHP uses mysqli query() or mysql_query() function to select records in a MySQL table using Like clause. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to select records in a MySQL table using Like Clause.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to select a record using like clause in a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Using Like Clause</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             $sql = ''SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl where tutorial_author like "Mah%"
             $result = $mysqli->query($sql);
    
             if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                   printf("Id: %s, Title: %s, Author: %s, Date: %d <br />",
                      $row["tutorial_id"],
                      $row["tutorial_title"],
                      $row["tutorial_author"],
                      $row["submission_date"]);
                }
             } else {
                printf(''No record found.<br />'');
             }
             mysqli_free_result($result);
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output. Here we”ve entered multiple records in the table before running the select script.

    Connected successfully.
    Id: 1, Title: MySQL Tutorial, Author: Mahesh, Date: 2021
    Id: 2, Title: HTML Tutorial, Author: Mahesh, Date: 2021
    Id: 3, Title: PHP Tutorial, Author: Mahesh, Date: 2021
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Where Clause nhận dự án làm có lương

    PHP & MySQL – Where Clause Example



    PHP uses mysqli query() or mysql_query() function to select records in a MySQL table using where clause. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to select records in a MySQL table using Where Clause.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to select a record using where clause in a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Using Where Clause</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             $sql = ''SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl where tutorial_author = "Mahesh"
             $result = $mysqli->query($sql);
    
             if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                   printf("Id: %s, Title: %s, Author: %s, Date: %d <br />",
                      $row["tutorial_id"],
                      $row["tutorial_title"],
                      $row["tutorial_author"],
                      $row["submission_date"]);
                }
             } else {
                printf(''No record found.<br />'');
             }
             mysqli_free_result($result);
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output. Here we”ve entered multiple records in the table before running the select script.

    Connected successfully.
    Id: 1, Title: MySQL Tutorial, Author: Mahesh, Date: 2021
    Id: 2, Title: HTML Tutorial, Author: Mahesh, Date: 2021
    Id: 3, Title: PHP Tutorial, Author: Mahesh, Date: 2021
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Using Joins nhận dự án làm có lương

    PHP & MySQL – Using Joins Example



    PHP uses mysqli query() or mysql_query() function to get records from a MySQL tables using Joins. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to get records from multiple tables using Join.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    First create a table in MySQL using following script and insert two records.

    create table tcount_tbl(
       tutorial_author VARCHAR(40) NOT NULL,
       tutorial_count int
    );
    
    insert into tcount_tbl values(''Mahesh'', 3);
    insert into tcount_tbl values(''Suresh'', 1);
    

    Example

    Try the following example to get records from a two tables using Join. −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Using joins on MySQL Tables</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             $sql = ''SELECT a.tutorial_id, a.tutorial_author, b.tutorial_count
    				FROM tutorials_tbl a, tcount_tbl b
    				WHERE a.tutorial_author = b.tutorial_author
             $result = $mysqli->query($sql);
    
             if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                   printf("Id: %s, Author: %s, Count: %d <br />",
                      $row["tutorial_id"],
                      $row["tutorial_author"],
                      $row["tutorial_count"]);
                }
             } else {
                printf(''No record found.<br />'');
             }
             mysqli_free_result($result);
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Id: 1, Author: Mahesh, Count: 3
    Id: 2, Author: Mahesh, Count: 3
    Id: 3, Author: Mahesh, Count: 3
    Id: 5, Author: Suresh, Count: 1
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Delete Records nhận dự án làm có lương

    PHP & MySQL – Delete Records Example



    PHP uses mysqli query() or mysql_query() function to delete records in a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to delete records in a MySQL table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to delete a record in a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Deleting MySQL Table record</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
             if ($mysqli->query(''DELETE FROM tutorials_tbl where tutorial_id = 4'')) {
                printf("Table tutorials_tbl record deleted successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not delete record from table: %s<br />", $mysqli->error);
             }
             $sql = "SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl";
    
             $result = $mysqli->query($sql);
             if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                   printf("Id: %s, Title: %s, Author: %s, Date: %d <br />",
                      $row["tutorial_id"],
                      $row["tutorial_title"],
                      $row["tutorial_author"],
                      $row["submission_date"]);
                }
             } else {
                printf(''No record found.<br />'');
             }
             mysqli_free_result($result);
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output. Here we”ve entered multiple records in the table before running the select script.

    Connected successfully.
    Table tutorials_tbl record deleted successfully.
    Id: 1, Title: MySQL Tutorial, Author: Mahesh, Date: 2021
    Id: 2, Title: HTML Tutorial, Author: Mahesh, Date: 2021
    Id: 3, Title: PHP Tutorial, Author: Mahesh, Date: 2021
    Id: 5, Title: Apache Tutorial, Author: Suresh, Date: 2021
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Update Records nhận dự án làm có lương

    PHP & MySQL – Update Records Example



    PHP uses mysqli query() or mysql_query() function to update records in a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to update records in a MySQL table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to update a record in a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Updating MySQL Table</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             if ($mysqli->query(''UPDATE tutorials_tbl set tutorial_title = "Learning Java" where tutorial_id = 4'')) {
                printf("Table tutorials_tbl updated successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not update table: %s<br />", $mysqli->error);
             }
    
             $sql = "SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl";
    
             $result = $mysqli->query($sql);
    
             if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                   printf("Id: %s, Title: %s, Author: %s, Date: %d <br />",
                      $row["tutorial_id"],
                      $row["tutorial_title"],
                      $row["tutorial_author"],
                      $row["submission_date"]);
                }
             } else {
                printf(''No record found.<br />'');
             }
             mysqli_free_result($result);
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output. Here we”ve entered multiple records in the table before running the select script.

    Connected successfully.
    Table tutorials_tbl updated successfully.
    Id: 1, Title: MySQL Tutorial, Author: Mahesh, Date: 2021
    Id: 2, Title: HTML Tutorial, Author: Mahesh, Date: 2021
    Id: 3, Title: PHP Tutorial, Author: Mahesh, Date: 2021
    Id: 4, Title: Learning Java, Author: Mahesh, Date: 2021
    Id: 5, Title: Apache Tutorial, Author: Suresh, Date: 2021
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Select Records nhận dự án làm có lương

    PHP & MySQL – Select Records Example



    You can use the same SQL SELECT command into a PHP function mysql_query(). This function is used to execute the SQL command and then later another PHP function mysql_fetch_array() can be used to fetch all the selected data. This function returns the row as an associative array, a numeric array, or both. This function returns FALSE if there are no more rows.

    The following program is a simple example which will show how to fetch / display records from the tutorials_tbl table.

    Example

    The following code block will display all the records from the tutorials_tbl table.

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Selecting Records</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
    
             if(! $conn ) {
                die(''Could not connect: '' . mysqli_error($conn));
             }
             echo ''Connected successfully<br />
    
             mysqli_select_db( $conn, ''TUTORIALS'' );
             $sql = "SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl";
             $retval = mysqli_query( $conn, $sql );
             if(! $retval ) {
                die(''Could not get data: '' . mysqli_error($conn));
             }
    
             while($row = mysqli_fetch_array($retval, MYSQL_ASSOC)) {
                echo "Tutorial ID :{$row[''tutorial_id'']}  ".
                   "Title: {$row[''tutorial_title'']} ".
                   "Author: {$row[''tutorial_author'']} ".
                   "Submission Date : {$row[''submission_date'']} ".
                   "--------------------------------";
             }
             echo "Fetched data successfullyn";
             mysqli_close($conn);
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server, enter details and verify the output on submitting the form.

    Entered data successfully
    

    While doing a data insert, it is best to use the function get_magic_quotes_gpc() to check if the current configuration for magic quote is set or not. If this function returns false, then use the function addslashes() to add slashes before the quotes.

    You can put many validations around to check if the entered data is correct or not and can take the appropriate action.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Create Tables nhận dự án làm có lương

    PHP & MySQL – Create Table



    PHP uses mysqli query() or mysql_query() function to create a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to create a MySQL table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to create a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Creating MySQL Table</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
             $sql = "CREATE TABLE tutorials_tbl( ".
                "tutorial_id INT NOT NULL AUTO_INCREMENT, ".
                "tutorial_title VARCHAR(100) NOT NULL, ".
                "tutorial_author VARCHAR(40) NOT NULL, ".
                "submission_date DATE, ".
                "PRIMARY KEY ( tutorial_id )); ";
             if ($mysqli->query($sql)) {
                printf("Table tutorials_tbl created successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not create table: %s<br />", $mysqli->error);
             }
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Table tutorials_tbl created successfully.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Drop Database nhận dự án làm có lương

    PHP & MySQL – Drop Database Example



    PHP uses mysqli query() or mysql_query() function to drop a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to drop a MySQL database.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to drop a database −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head><title>Dropping MySQL Database</title></head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             if ($mysqli->query("Drop DATABASE TUTORIALS")) {
                printf("Database TUTORIALS dropped successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not drop database: %s<br />", $mysqli->error);
             }
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Database TUTORIALS dropped successfully.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Insert Records nhận dự án làm có lương

    PHP & MySQL – Insert Records Example



    PHP uses mysqli_query function to insert records in table. This function takes three parameters and returns TRUE on success or FALSE on failure.

    Syntax

    mysqli_query ( mysqli $link, string $query, int $resultmode = MYSQLI_STORE_RESULT ) : mixed
    

    Sr.No. Parameter & Description
    1

    $link

    Required – A link identifier returned by mysqli_connect() or mysqli_init().

    2

    $query

    Required – SQL query to drop a table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    This example will take three parameters from the user and will insert them into the MySQL table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Add New Record in MySQL Database</title>
       </head>
       <body>
          <?php
             if(isset($_POST[''add''])) {
                $dbhost = ''localhost
                $dbuser = ''root
                $dbpass = ''root@123
                $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
    
                if(! $conn ) {
                   die(''Could not connect: '' . mysqli_error($conn));
                }
                if(! get_magic_quotes_gpc() ) {
                   $tutorial_title = addslashes ($_POST[''tutorial_title'']);
                   $tutorial_author = addslashes ($_POST[''tutorial_author'']);
                } else {
                   $tutorial_title = $_POST[''tutorial_title''];
                   $tutorial_author = $_POST[''tutorial_author''];
                }
                $submission_date = $_POST[''submission_date''];
                $sql = "INSERT INTO tutorials_tbl ".
                   "(tutorial_title,tutorial_author, submission_date) "."VALUES ".
                   "(''$tutorial_title'',''$tutorial_author'',''$submission_date'')";
                mysqli_select_db( $conn, ''TUTORIALS'' );
                $retval = mysqli_query( $conn, $sql );
    
                if(! $retval ) {
                   die(''Could not enter data: '' . mysqli_error($conn));
                }
                echo "Entered data successfullyn";
                mysqli_close($conn);
             } else {
          ?>
          <form method = "post" action = "<?php $_PHP_SELF ?>">
             <table width = "600" border = "0" cellspacing = "1" cellpadding = "2">
                <tr>
                   <td width = "250">Tutorial Title</td>
                   <td><input name = "tutorial_title" type = "text" id = "tutorial_title"></td>
                </tr>
                <tr>
                   <td width = "250">Tutorial Author</td>
                   <td><input name = "tutorial_author" type = "text" id = "tutorial_author"></td>
                </tr>
                <tr>
                   <td width = "250">Submission Date [   yyyy-mm-dd ]</td>
                   <td><input name = "submission_date" type = "text" id = "submission_date"></td>
                </tr>
                <tr>
                   <td width = "250"> </td>
                   <td></td>
                </tr>
                <tr>
                   <td width = "250"> </td>
                   <td><input name = "add" type = "submit" id = "add"  value = "Add Tutorial"></td>
                </tr>
             </table>
          </form>
       <?php
          }
       ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server, enter details and verify the output on submitting the form.

    Entered data successfully
    

    While doing a data insert, it is best to use the function get_magic_quotes_gpc() to check if the current configuration for magic quote is set or not. If this function returns false, then use the function addslashes() to add slashes before the quotes.

    You can put many validations around to check if the entered data is correct or not and can take the appropriate action.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc