Tech blog

PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Tuesday 31 March 2015

Simple Registration using PHP

2 comments :
Hello Friends, As we have went through many topics like login,login with facebook,login with google,sms sending api,ffmpeg.But each and every website needs user to register on their website.they want user to be in touch with their website all time.Also they store data of user on website.For that one process is necessary which is known as registration.
All language like .NET,PHP,JAVA has codes to do registration.Even wordpress,drupal also do same.

But as PHP developer and being writing PHP codes,here i need to explain you how registration works and how code is implement.

First of all i will explain you process for same.


  • User come for visit on you website and signup for registration.
  • When he goes on registration page,he fills simple information form on your site and submit it.
  • All information which he inputs,they get stored into database.



Let's See this process in form of code:

HTML to create Form

index.php

<html>
<body>
<form action="" method="POST" name="form1" id="form1">
<label>Name:</label>
<input type="text" id="your_name" name="your_name" value=""/>
<label>User Name:</label>
<input type="text" id="user_name" name="user_name" value=""/>
<label>Password:</label>
<input type="text" id="pass" name="pass" value=""/>
<label>Confirm Password:</label>
<input type="text" id="c_pass" name="c_pass" value=""/>
<input type="submit" id="submit" name="submit" value="Submit"/>
</form>
</body>
</html>

PHP Code to store information:

 index.php

paste this code upside of html in same file.

<?php
include('connect.php');
if(isset($_POST['submit']))
{
$your_name=$_POST['your_name'];
$user_name=$_POST['user_name'];
$pass=$_POST['pass'];
$insert="INSERT INTO users SET name='".$your_name."',user_name='".$user_name."',password='".$pass."'";
$res=mysql_query($insert) or die(mysql_error());
$id=mysql_insert_id();
if($id > 0)
{
header('location:index.php?msg=1');
}
else
{
header('location:index.php?msg=2');
}
}
?>
 connect.php

<?php
$host="your_host_name";
$username="your_username";
$password="your_password";
$db="your_db_name";
$link=mysql_connect($host,$username,$password);
mysql_select_db($db,$link);
?>

Create database and make one table named "user" with fields username,password,name and other fields which you want from user to get stored.

run code...!!

Tuesday 3 March 2015

Online Voting System

No comments :
Hello Friends,Today I came with small application on this blog.I am sure you will like it.This system is name as "online voting system".

In this system,Right now voting functionality is shown.voting questions and options are static and also user is also static.



Here are two files are used and one database with one table.

config.php

<?php
$host="localhost";
$username="root";
$password="";
$db="test";
$link=mysql_connect($host,$username,$password);
mysql_select_db($db,$link);

?>

voting.php

<?php
include('config.php');
if(isset($_POST['submit1']))
{
$vote=$_POST['actor'];
$INSERT="insert into votes SET user_id='".$_SESSION['id']."',answer='".$vote."',create_date='now()'";
$res=mysql_query($INSERT) or die(mysql_error());
if(mysql_insert_id() > 0)
{
header("location:voting.php?msg=1");
}
}
$select="select * from votes where id>0";
$res1=mysql_query($select) or die(mysql_error());
$tot=mysql_num_rows($res1);
if(mysql_num_rows($res1) > 0)
{
    $answer1=0;
$answer2=0;
$answer3=0;
$answer4=0;
while($row_s=mysql_fetch_array($res1))
{
if($row_s['answer']==1)
{
$answer1+=1;
$per1=($answer1/$tot) * 100;
}
else if($row_s['answer']==2)
{
$answer2+=1;
$per2=($answer2/$tot) * 100;
}
else if($row_s['answer']==3)
{
$answer3+=1;
$per3=($answer3/$tot) * 100;
}
else if($row_s['answer']==4)
{
$answer4+=1;
$per4=($answer4/$tot) * 100;
}
}
}
?>
<html>
<head>
<title>Online Voting System</title>
</head>
<body>
<?php if($_GET['msg']==1){?><span style="background:green;color:#FFF;border-radius:5px;font-size:14px;width:100%;height:100%;">Your vote is submitted successfully</span><?php } ?><br/>
<?php echo 'Total Votes          '.$tot;?>
<div style="">
<span>Arjun Kapoor <?=$answer1;?>  <?= $per1.'%';?></span><br/>
<span>Ranvir Kapoor <?=$answer2;?> <?= $per2.'%';?></span><br/>
<span>Rabir Kapoor <?=$answer3;?>  <?= $per3.'%';?></span><br/>
<span>Varun Dhawan <?=$answer4;?>  <?= $per4.'%';?></span><br/>
</div>
<h1>Who will take place of superstar?</h1>
<form id="voteform" name="voteform" action="" method="post">
<input type="radio" name="actor" id="actor" value="1">Arjun Kapoor<br/>
<input type="radio" name="actor" id="actor" value="2">Ranvir Kapoor<br/>
<input type="radio" name="actor" id="actor" value="3">Rabir Kapoor<br/>
<input type="radio" name="actor" id="actor" value="4">Varun Dhawan<br/>
<input type="submit" name="submit1" id="submit1" value="Vote"/>
</form>
</body>

</html>

Database table structure:

table name:votes.
fields:id,user_id,answer,create_date


Integrate this code into your files.Enjoy coding!!!!