Results 1 to 9 of 9

Thread: Day 14 - Storing Data in MySQL - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/msqlmsg.php

    Code:
    <?php
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {
        echo 'Connect failed: ' . $mysqli->connect_error;
        exit();
    }
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Neena\', `message`=\'To acquire knowledge, one must study;
    but to acquire wisdom, one must observe\'';
    
    if ($mysqli->query($sql) === TRUE) {
        echo '<h1>Data saved into MYSQL</h1>';
    } else {
        echo '<h1>Failed to Insert Data to Database</h1>';
        echo $mysqli->error;
    }

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sherlyk View Post
    http://php.flashwebhost.com/sherly/msqlmsg.php

    Code:
    <?php
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {
        echo 'Connect failed: ' . $mysqli->connect_error;
        exit();
    }
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Neena\', `message`=\'To acquire knowledge, one must study;
    but to acquire wisdom, one must observe\'';
    
    if ($mysqli->query($sql) === TRUE) {
        echo '<h1>Data saved into MYSQL</h1>';
    } else {
        echo '<h1>Failed to Insert Data to Database</h1>';
        echo $mysqli->error;
    }
    Good, only problem is when ever some one visit the page, this data get inserted. That is not an issue as we have no real use for this MySQL database or table.

    It will be nice if we show an HTML form with 2 fields. Name and Message, when user submit, data get stored in database, so every time new message can be inserted to MySQL.

    For now, we understand how to store data into mysql, that will be fine for now.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  3. #3
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    http://php.flashwebhost.com/annie/mysql_insert.php

    Code:
     <?php
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {
        echo 'Connect failed: ' . $mysqli->connect_error;
        exit();
    }
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Priya\', `message`=\'Optimism is essential to achievement and it is also the foundation of courage and true progress.
    \'';
    
    if ($mysqli->query($sql) === TRUE) {
        echo '<h1>Data saved into MYSQL</h1>';
    } else {
        echo '<h1>Failed to Insert Data to Database</h1>';
        echo $mysqli->error;
    }

  4. #4
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by annie View Post
    http://php.flashwebhost.com/annie/mysql_insert.php

    Code:
     <?php
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {
        echo 'Connect failed: ' . $mysqli->connect_error;
        exit();
    }
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Priya\', `message`=\'Optimism is essential to achievement and it is also the foundation of courage and true progress.
    \'';
    
    if ($mysqli->query($sql) === TRUE) {
        echo '<h1>Data saved into MYSQL</h1>';
    } else {
        echo '<h1>Failed to Insert Data to Database</h1>';
        echo $mysqli->error;
    }
    Good, you can see inserted data on page

    http://php.flashwebhost.com/annie/mysql.php
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  5. #5
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/mysql_connect.php
    Code:
    <?php 
    
    
    $db_server = '127.0.0.1'; 
    $db_user = 'fwhphp_user'; 
    $db_password = 'k5BJRaX6SFbs'; 
    $db_name = 'fwhphp_db'; 
    
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name); 
    
    
    if ($mysqli->connect_errno) { 
        echo 'Connect failed: ' . $mysqli->connect_error; 
        exit(); 
    } 
    
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Stefin\', `message`=\'Childhood is the happiest time of life. Be Happy and enjoy your Childhood.\''; 
    
    
    if ($mysqli->query($sql) === TRUE) { 
        echo '<h1>Data saved into MYSQL</h1>'; 
    } else { 
        echo '<h1>Failed to Insert Data to Database</h1>'; 
        echo $mysqli->error; 
    }

  6. #6
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    http://php.flashwebhost.com/stefin/mysql_connect.php
    Code:
    <?php 
    
    
    $db_server = '127.0.0.1'; 
    $db_user = 'fwhphp_user'; 
    $db_password = 'k5BJRaX6SFbs'; 
    $db_name = 'fwhphp_db'; 
    
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name); 
    
    
    if ($mysqli->connect_errno) { 
        echo 'Connect failed: ' . $mysqli->connect_error; 
        exit(); 
    } 
    
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Stefin\', `message`=\'Childhood is the happiest time of life. Be Happy and enjoy your Childhood.\''; 
    
    
    if ($mysqli->query($sql) === TRUE) { 
        echo '<h1>Data saved into MYSQL</h1>'; 
    } else { 
        echo '<h1>Failed to Insert Data to Database</h1>'; 
        echo $mysqli->error; 
    }

    Nice, working perfectly and good message :)

    You can see the data from MySQL on page

    http://php.flashwebhost.com/stefin/mysql_1.php
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  7. #7
    Join Date
    Apr 2005
    Posts
    46,704

    Default

    http://php.flashwebhost.com/mini/mysql_data.php

    Code:
    <?php
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {
        echo 'Connect failed: ' . $mysqli->connect_error;
        exit();
    }
    
    $sql = 'INSERT INTO `chat` SET `name`=\'Jiya\', `message`=\'My school days were the happiest days of my life\'';
    
    if ($mysqli->query($sql) === TRUE) {
        echo '<h1>Data saved into MYSQL</h1>';
    } else {
        echo '<h1>Failed to Insert Data to Database</h1>';
        echo $mysqli->error;
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •