Your SlideShare is downloading. ×
Mysql Script
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Mysql Script

2,635
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,635
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP-MYSQL
    Script
  • 2. PHP FORM
    <?php
    require_once ('mysql/mysql_connect.php');
    if (isset($_POST['submit'])) { // Handle the form.
    {
    // Add name to the database.
    $query = "INSERT INTO your_table (first_name) VALUES ('$first_name')";
    if ($result = @mysql_query ($query)) { // Worked.
    echo '<p>The name has been saved.</p>';
    } else { // If the query did not run OK.
    echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>';
    }
    } else { // Failed a test.
    echo '<p><font color="red">Please click "back" and try again.</font></p>';
    }
    } else { // Display the form.
    ?>
  • 3. PHP FORM CONTINUATION
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div id="content">
    <h2>
    Add Name</h2>
    </div>
    <table>
    <tr>
    <td>First Name:</td>
    <td><input type="text" name="first_name" size="30" maxlength="30" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></td>
    </tr>
    </table>
    <div align="center"><input type="submit" name="submit" value="Submit" /></div>
     
    </form><!-- End of Form -->
    <?php
    } // End of main conditional.
    ?>
  • 4. Mysql Connect
    <?php
    // This file contains the database access information for the database. This file also establishes a connection to MySQL and selects the database.
     
    define ('DB_USER', 'root');
    define ('DB_PASSWORD', '');
    define ('DB_HOST', 'localhost');
    define ('DB_NAME', '');
     
    // Make the connnection and then select the database.
    $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
    mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
     
    // Function for escaping and trimming form data.
    function escape_data ($data) {
    global $dbc;
    if (ini_get('magic_quotes_gpc')) {
    $data = stripslashes($data);
    }
    return mysql_real_escape_string (trim ($data), $dbc);
    } // End of escape_data() function.
    ?>

×