SIMPLE DATA ENTRY IN MYSQL DATABASE USING PHP

You may find a hell lot of tutorials on this topic, but may not work on your system because of what PHP version you are using! So, I'd also like to share a simple data entry into MySQL database using PHP! It may work with your system! :D

Note: For Beginner!

It'll be very short and simple, so that you can understand the whole code easily!

For this I will be using XAMPP (Apache) as a server ,specifically, version 5.5.37 , you may want to download it if you are going to follow this tutorial!

Depending on the Operating System you are using, you should download them!

For Windows User:

Just Install It! Hope you know how to install!

For Linux Users:



Now, to install into your system,
Go to Terminal.
Give the following commands:
cd /path-to-your-file
sudo chmod +x xampp-linux-x64-5.5.37-0-installer.run
sudo ./xampp-linux-x64-5.5.37-0-installer.run

I will not talk about Mac version as I haven't done on it!

Now, we can begin the coding! All our code should be located inside the htdocs folder of your xampp/lampp installation directory i.e. our workspace will be htdocs folder!

If you wonder where htdocs folder is;

For Windows user, the htdocs folder is usually in
C:/xampp/htdocs

For Linux users, it is inside /opt/lampp/htdocs
For this data entry, we will create only one file!
But, before that we will first explain each part one by one!
To enter data into the database we need to connect to the database first! And to connect to a database, we must have a database! LOL!
So, Lets create one database by going to http://127.0.0.1/phpmyadmin or http://localhost/phpmyadmin. Lets create one new database called directory!
Let's go to the SQL tab and enter the following query!

CREATE TABLE `members` (
  `id` int(11) NOT NULL,
  `name` varchar(50) NOT NULL,
  `phone` varchar(12) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Now, we have our database directory with a table members ! Lets start the connection!
Connection to the database can be created in a number of ways; mysqli (procedural), mysqli (object oriented) and pdo! Now, we are going to use procedural mysqli!
The connection to database is created as below:

<?php
$dbcon = @mysqli_connect("localhost","root","","directory");
if($dbcon){
    echo "";
}
else{
    echo "Error!";
}
?>

Before going further, lets create a simple html form!

<!DOCTYPE html>
<html>
<head>
    <title>Simple Data Entry</title>
</head>
<body style="max-width:600px;margin:auto;align:justify;padding:8px;">
<form action="entry.php" method="post">
<legend>PLEASE FILL UP!</legend><br/>
<label for="name">ENTER NAME:</label><br/>
    <input type="text" name="name"><br/>
<label for="phone">ENTER PHONE NUMBER:</label><br/>
    <input type="tel" name="phone"><br/>
<br/>
    <input type="hidden" name="submitinfo" value="TRUE">
    <input type="submit">
</form>
</body>
</html>

Now if any field is empty, we will notify that a field is empty! For that, we will require an array where we will store the error message!

$error = array();

To check whether a field is empty, we will use empty() library function as below:

if(!empty($_POST['name']))
        $name = $_POST['name'];
    else
        $error[] = "Please Enter Name!";

Now, if the error[] array is empty, we will insert data from html form into the database as below:

$query = "INSERT INTO `members` (`name`,`phone`) VALUES('$name','$phone')";

        $insert = mysqli_query($dbcon,$query);

Now, we can say that we are done!


Lets take a look at the while code.

<?php
//Lets connect the database....
$dbcon = @mysqli_connect("localhost","root","","directory");
if($dbcon){
    echo "";
}
else{
    echo "Error!";
}

//create one array to store error message....

$error = array();

//Let assign our html form data to our variables...

if(isset($_POST['submitinfo'])){ //if submit button is clicked!

    if(!empty($_POST['name']))
        $name = $_POST['name'];
    else
        $error[] = "Please Enter Name!";

    if(!empty($_POST['phone']))
        $phone = $_POST['phone'];
    else
        $error[] = "Please Enter Phone Number!";

    if(empty($error)){

        $query = "INSERT INTO `members` (`name`,`phone`) VALUES('$name','$phone')";

        $insert = mysqli_query($dbcon,$query);
        if(!$insert){
            echo "Query Failed!";
        }
        if(mysqli_affected_rows($dbcon)==1){
            echo "New Data Inserted!";
        }else{
            echo "Error!";

         }

    }else{
        echo '<ol>';

        foreach ($error as $key => $values) {

            echo '  <li>'.$values.'</li>';

        }
        echo '</ol>';
    }
    mysqli_close($dbcon);
}


?>

<!-- html form -->
<!DOCTYPE html>
<html>
<head>
    <title>Simple Data Entry</title>
</head>
<body style="max-width:600px;margin:auto;align:justify;padding:8px;">
<form action="<?php $_PHP_SELF; ?>" method="post">
<legend>PLEASE FILL UP!</legend><br/>
<label for="name">ENTER NAME:</label><br/>
    <input type="text" name="name"><br/>
<label for="phone">ENTER PHONE NUMBER:</label><br/>
    <input type="tel" name="phone"><br/>
<br/>
    <input type="hidden" name="submitinfo" value="TRUE">
    <input type="submit">
</form>
</body>
</html>

Name this file anything as you wanted (should be .php extension) and open your browser and go to http://localhost/your_file_name.php!

Enter any data, if there is anything wrong, please say it in the comment section!
Share:

NLP AND ME! - E1

I have been working as a undergrad researcher on the topic of  "Natural Language Processing" for like one year now, and I haven't write any details about it!

I made a post about some introduction to Mizo language processing. I mainly focus on Machine Translation only, and that is also very basic introduction! So, I'd like to share a few things that I knew about Natural Language Processing. I will make post about NLP  in series , because NLP is a very vast field and consist of many sub-topics.

It will not be like a lecture or instruction, but merely my opinions and my ideas. Some of it may be wrong, may not be applicable in NLP. But still, I'd like to share my opinions!

Me and my colleagues are working on Information Retrieval for Indian Languages, mainly Mizo language! Our research paper haven't published yet, so I will speak later.

Last winter vacation i.e December 2015 to January 2016, we are working on Mizo Parts of Speech Tagging, which is the first time for Mizo language. We have also created Mizo POS Tagger, which will soon be available to download for public!

Mizo language, in particular, have lots of ambiguity! Sometimes working on it makes me feel very dizzy! But, as I am working with a great programmer and a brilliant mind, we are able to overcome most of  the ambiguities!

Part of Speech Tagging for Mizo somehow requires a good knowloedge of grammar! Since POST is one of the very important piece of NLP, there no other option other than to solve the ambiguities.

If you may wonder what's the neccessities of it, you can see one application called Stanford Parser. Each word in a sentence is a part of  part of speech!

Consider a sentence:

Jeremy is a good programmer living in India

If you parse it in Stanford Parser, you will find the POS tagging result as:


Jeremy/NNP
is/VBZ
a/DT
good/JJ
programmer/NN
living/VBG
in/IN
India/NNP


NNP, NN, VBG, VBZ, JJ, DT, etc. are the part of speech tags! Different language will have different POS tags as the part of speech for different language is different!

If you wanna read more about Part of Speech tagging, you could find more about it in Wikipedia.
Like I said, I don't have a deep knowledge about POS tagging, I better not talk much about it!

One thing I knew about NLP is that, before we let our machine do work on its own, we have to do it for them manually!
Our POS tagger is also one such application which will be used to tag a POS manually! Once we finished all the documentation , I will share it for download! May be someday it will be one important tool for future researchers of Mizo NLP!
Share:

XAMPP CONFIGURATION FOR (ONLINE) WEBSITE

I don't think this is a new thing for most of you! But,  I'd still like to share this things that I found out!

During this vacation ( Summer 2016 ), I continue my internship at my very own college NIT Mizoram, with my colleague Jereemi Bentham (Genius) ! We are building a Mizo Search Engine based on Apache Nutch. So many works to do as we are the first one on this topic! After the publication of our Research Paper, I'd share the procedure of the task!

But for now, as mentioned in the title, I will share one thing I found out about XAMPP configuration!

During this internship period, I was given extra work to create an Internet User Management System (Web based)! Our college server (IIS) have some problem with PHP and other web language except ASP! As a PHP Developer, I don't know much about ASP!

So, I thought of using XAMPP and make some modification in the configuration! So, I install XAMPP Server and make the configuration as below!

First the httpd.conf file:

Path : C:\xampp\apache\conf\httpd.conf


Changes:

Now, make some changes in your httpd.conf . First, search for the following line of configuration!

ServerAdmin postmaster@localhost

This isn't necessary if you are not going to use email service! But if you want to use, change it as below!


ServerAdmin email@your_website.com

Second, find the following lines again.

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">


 This is important! By default, when you start a XAMPP server and go to http://localhost or http://127.0.0.1, you will be redirected to http://localhost/dashboard or http://127.0.0.1/dashboard. If you want to make your own website as the default home page of localhost, you have to change the above lines as:

 DocumentRoot "C:/xampp/htdocs/YourWebsiteRootFolder"
<Directory "C:/xampp/htdocs/YourWebsiteRootFolder">

Also know that your website folder must be placed inside htdocs folder!


Now, we are all good with the httpd.conf file. But, in case we want to use email service, XAMPP, by default will not allow sendmail() function of your PHP! You will have to hack the configuration file again!

But for now, I will not talk about it! I'll soon get back! I do not like a long post at a time!
Share:

SOME SH*T IN MY LIFE - E1

Sh*t! Big problem! I have no extra money to renew my domain!Why would I pay for a domain while I can hardly pay for my lunch! :D
Last year, I bought www.sundayamizo.in from Crazydomains.in at Rs. 99 for 1 year. Now, I have to renew it for like Rs. 1000 which I, currently, did not have.

But I am confident that no one in this world will buy it before I do! I receive this renewal alert email from Crazy Domains daily since last month! Even thought its very safe (from other domain buyers), the fear of losing it always kept haunting my mind!

By the way, I have so many problem with Crazy Domains! First thing, the website looks like a junk when accessing it from my home internet! Its OK if I use some VPN. As shown below, it has no CSS at all! Difficult to use the service! What is wrong with my home IP address!


This is how it looks from my IP.

My second problem with Crazy Domains is that I can't configure some CNAME records while trying to add blog.sundayamizo.in which is for my blog www.sundayamizo.ga! Because of that, I use free domain from Freenom, my favorite free domain provider!

My problem with Crazy Domains may be because I am a cheap customer! But, atleast they should provide an email service. Also, their customer care is also very bad!

So, next time, if I can renew my domain, I better change my domain provider. May be BigRock!

Also, another big problem with my home IP is that I can't access  my XtGem account from this f**king address! I have no idea what mistake I have done! As you may have read one of my post on mobile web development, XtGem is a very important part in my web development world till today!

Why the hell should my IP be blacklisted?

I'm sure I am free from any type of virus that can affect my virus!

Why is this sh*t happening?

Share: