How To Build A Simple Chat System In PHP, HTML, CSS, Javascript (PART1 )

By Mark Chidozie   2 years ago   600
Programming

<?php
if(isset($_POST['name']) && !isset($display_case)){
 $name=htmlspecialchars($_POST['name']);
 $sql=$dbh->prepare("SELECT name FROM chatters WHERE name=?");
 $sql->execute(array($name));
 if($sql->rowCount()!=0){
  $ermsg="<h2 class='error'>Name Taken. <a href='index.php'>Try another Name.</a></h2>";
 }else{
  $sql=$dbh->prepare("INSERT INTO chatters (name,seen) VALUES (?,NOW())");
  $sql->execute(array($name));
  $_SESSION['user']=$name;
 }
}elseif(isset($display_case)){
 if(!isset($ermsg)){
?>
 <h2>Name Needed For Chatting</h2>
 You must provide a name for chatting. This name will be visible to other users.<br/><br/>
 <form action="index.php" method="POST">
  <div>Your Name : <input name="name" placeholder="A Name Please"/></div>
  <button>Submit & Start Chatting</button>
 </form>
<?php
 }else{
  echo $ermsg;
 }
}
?>
THAT WAS THE LOGIN PART, WATCH OUT FOR THE NEXT ONE

[NewsNaira]


Share this article!


Login to comment and earn


Godwin John
2 years ago

Thank for this information 


(Quote) (Likes)
Onalimi Lukel
1 year ago

Thank you for your information


(Quote) (Likes: 1)
James
1 year ago

Rghhbv ghyjnvc 


(Quote) (Likes: 2)
Henry Smith
1 year ago

Thank for this information

good


(Quote) (Likes)
Gerard Omeni
1 year ago

Nice information


(Quote) (Likes)

The info in good oo


(Quote) (Likes)

It is all about orientation


(Quote) (Likes)
Chidi Okpan
1 year ago

Very Educative one


(Quote) (Likes)