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
Login to comment and earn
2 years ago
Thank for this information
1 year ago
Thank you for your information
1 year ago
Rghhbv ghyjnvc
1 year ago
Thank for this information
good
1 year ago
Nice information
1 year ago
The info in good oo
1 year ago
It is all about orientation
1 year ago
Very Educative one