User registration & Login System(php,mysql) - mysql

I have made user registration & login system. But i have problems in my form, when new user signup it must provide first name, last name, email, phone and password. After signup if an other user signup with different phone number but same email it also got sign up. So i need to signup those user's who have different phone and email. In simply words i need to remove repetitions.
My html code is as follow:
<form action="#" method="post">
<input class="form-control" type="text" placeholder="First Name" required name="fname" >
<input class="form-control" type="text" placeholder="Last Name" required name="lname" >
<input class="form-control" type="text" placeholder="Enter your phone number"
id="phonecheck"name="phone"
<input class="form-control" type="password" placeholder="Enter Password" required name="password" >
<button class="btn btn-primary" type="submit" name="btnreg"><i class="fa fa-check-square"></i> Sign Up</button>
</form>
My php code:
<?php if (isset($_POST['btnreg'])) {
include 'connection.php';
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$password=$_POST['password'];
$sql=mysqli_query($con,"select * from tblusers where phone='".$phone."' AND email='".$email."'");
$numrows=mysqli_num_rows($sql);
if ($numrows==0)
{
$sql="insert into tblusers (f_name,l_name,phone,email,password) values ('$fname','$lname','$phone','$email','$password') ";
$result=mysqli_query($con,$sql);
if ($result==true) {
echo "<script type = \"text/javascript\">
alert(\"Successfully Registered.\");
window.location = (\"login.php\")
</script>";
}
else {
echo "<script type =text/javascript>
alert(Registration Failed. Try Again);
window.location = ('signup.php')
</script>";
}
}
else {
echo "Email & Phone Number Already exists";
}
}
?>

To do this, you need to check the existence of the data in the database in the php code.
Check and if it does not exist, insert, or on the contrary, INSERT VALUES WHERE NOT EXISTS

Related

Attempt to read property "name" on array

I am trying to enter data inside database table via form. I have created an instance of Model and accessed the columns of that table and assigned the input names of form but when I enter data an submit it says Attempt to read property "name" on array. Can anyone guide me if there is anything wrong.
Code of Controller where im inserting datas to database
class UserController extends Controller
{
function registerUser(Request $req)
{
$data = $req->input();
$user_model = new User;
$user_model->fullname = $data->name;
$user_model->mobile = $data->mobile;
$user_model->email = $data->email;
$user_model->password = $data->password;
$user_model->save();
return "registered successfully";
}
}
Code of Form
<div class="register-form">
<h4>Sign Up</h4>
<form method="post" action="register">
#csrf
<input type="text" name="name" placeholder="Full Name" size="40">
<br>
<input type="tel" name="mobile" placeholder="Mobile number" size="40">
<br>
<input type="email" name="email" placeholder="Email" size="40">
<br>
<input type="password" name="password" placeholder="Password" size="40">
<br>
<input id="submit_btn" type="submit" placeholder="Sign Up" size="40">
<hr>
<p>Already, have an account <span href="#" id="sign-in-link">Log In</span></p>
</form>
</div>
function registerUser(Request $req)
{
$user_model = new User;
$user_model->fullname = $req->name;
$user_model->mobile = $req->mobile;
$user_model->email = $req->email;
$user_model->password = bcrypt($req->password); //laravel hashed password
$user_model->save();
return "registered successfully";
}
$req->input is an array. Access it like so.
$user_model->fullname = $data['name'];
$user_model->mobile = $data['mobile'];
$user_model->email = $data['email'];
$user_model->password = $data['password'];

Using if(isset($_POST[''])) method to see if the user enter the data so in will store them , and if not so will not save when i refresh the page

i want to use if(isset($_POST['name'])) loop to test if user enter data so it will store it in database and if not so dont store it even when i refresh the page!!
i've tried to use if(isset($_POST['name'])) loop to test if user enter data so it will store it in database and if not so dont store it even when i refresh the page but doesnt work ! and when i refresh the page it store the last data that i've tried before!!
this is index.php :
<!DOCTYPE html>
<html>
<body>
<ul><?php
require "controller/database.php";
require "controller/users.php";
$user=new Users();
$user->insertUser($_POST['name'],$_POST['age'],$_POST['email']);
?></ul>
<form action="" method="POST">
<input type="text" name="name" required placeholder="Name"><br><br>
<input type="number" name="age" required placeholder="Age" ><br><br>
<input type="text" name="email" required placeholder="Email" ><br><br>
<button type="submit" name="insert" value="Add Data To Database"></button>
</form>
</body>
</html>
this is the users.php file :
<?php
class Users extends DB {
function insertUser($name,$age,$email){
$query = "INSERT INTO users (name, age, email )
VALUES ('$name', '$age', '$email')";
$res=$this->insert($query);
//return $this->select("SELECT * FROM `users`");
}
}
i've tried to use if(isset($_POST['name'])) loop to test if user enter data so it will store it in database and if not so dont store it even when i refresh the page but doesnt work ! and when i refresh the page it store the last data that i've tried before!!
Please help!!
it show this error and store the data at the same time !
Notice: Undefined index: name in C:\xampp\htdocs\gestion de paie\index.php on line 10
Notice: Undefined index: age in C:\xampp\htdocs\gestion de paie\index.php on line 10
Notice: Undefined index: email in C:\xampp\htdocs\gestion de paie\index.php on line 10
You can put a condition before you create user, in index file
index.php
<!DOCTYPE html>
<html>
<body>
<ul><?php
require "controller/database.php";
require "controller/users.php";
if(isset($_POST['name']) && isset($_POST['age']) && isset($_POST['email']){
$user=new Users();
$user->insertUser($_POST['name'],$_POST['age'],$_POST['email']);
}
?></ul>
<form action="" method="POST">
<input type="text" name="name" required placeholder="Name"><br><br>
<input type="number" name="age" required placeholder="Age" ><br><br>
<input type="text" name="email" required placeholder="Email" ><br><br>
<button type="submit" name="insert" value="Add Data To Database"></button>
</form>
</body>
</html>
Also don't put user inputs inside a query without sanitize, i suggest always to controll user inputs before you enter in you sql query:
users.php :
<?php
class Users extends DB {
function insertUser($name,$age,$email){
// Sanitize your data always don't trust user
$name = mysql_real_escape_string($name);
$age = mysql_real_escape_string($age);
$email = mysql_real_escape_string($email);
$query = "INSERT INTO users (name, age, email )
VALUES ('$name', '$age', '$email')";
$res=$this->insert($query); //return $this->select("SELECT * FROM `users`");
Hope to be the needed question :)
Instead of isset, you should use !empty (look here), as isset doesn't work for arrays. isset($_POST["anything"]) always returns true, while !empty($_POST["anything"]) only returns true if $_POST["anything"] exists.
<!DOCTYPE html>
<html>
<body>
<ul><?php
require "controller/database.php";
require "controller/users.php";
if (!empty($_POST['name']) && !empty($_POST['age']) && !empty($_POST['email']) {
$user=new Users();
$user->insertUser($_POST['name'],$_POST['age'],$_POST['email']);
}
?></ul>
<form action="" method="POST">
<input type="text" name="name" required placeholder="Name"><br><br>
<input type="number" name="age" required placeholder="Age" ><br><br>
<input type="text" name="email" required placeholder="Email" ><br><br>
<button type="submit" name="insert" value="Add Data To Database"></button>
</form>
</body>
</html>
Also, you should use Prepared statements.

how to prompt password manager for username and password?

I have a html form for register user, what attribute should I put to prompt password manager (google/lastpass/onepass/etc) that the email address will be used as username upon submit?
<form>
<input type='text' placeholder='email address'><br>
<input type='text' placeholder='first name'><br>
<input type='text' placeholder='last name'><br>
<input type='text' placeholder='postcode'><br>
<input type='password' placeholder='password'><br>
<input type='password' placeholder='password again'><br>
<button type='submit'>register</button>
</form>
Most password managers use the name attribute for this purpose.
You need to provide one anyway so that the control can be successful and the data submitted to the server.

E-mail box for HTML website

So I have made myself a website. Since it has plans for being used I need someones help :)
I need users to fill in a few boxes and then send it to my email at thisismyemail#provider.com.
Since I am a little new I dont now how to do it.
The form: http://imgur.com/U5Q3jrE
This is my code:
<form action="../index.html" method="post" class="message">
<input type="text" value="Naam" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="E-mail" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="Onderwerp" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<textarea></textarea>
<input type="submit" value="Send"/>
</form>
Now what I need is that it doesnt bring me to the index page but show a message with someone like: "Your message has been send" and that it sends it to my email, because at the moment it doesnt send it to anything.
Once more I am pretty new so please forgive my noobness :P
Thanks everyone,
Waylon194
Ok here's a php html code that can be used to email, that you can start with.
User inputs must always be sanitized accordingly. This code is just for demonstration.
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone#example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>

HTTP POST to web login form. Joomla, INVALID TOKEN

I am trying to create a HTTP POST to a joomla web login form for a web page.
I used this before and I am not new to this but I am stumped, I cannot get any response other than 'invalid token'
The purpose of this is to have a POST that I can use for a mobile application to 'remember' the password as a temporary solution.
I HAVE used Charles to check the difference between the HTTP Requests and I see no difference between if I use the login form manually and if I use a POST in the URL
My Request is
http://www.example.com/member-login?task=user.login&username=SECRET&password=SECRET&return=aW5kZXgucGhwP29wdGlvbj1jb21fdXNlcnMmdmlldz1wcm9maWxl&1132a16eb61f5659e8ff62fb935f6037=1
The HTML code is
<form action="/member-login?task=user.login" method="post" class="form-horizontal" name="login_form">
<div class="joomla_login">
<fieldset class="input">
<h2>Login</h2>
<p>Login using the email address and the password that you used when you registered.</p>
<p>
<span class="add-on">
<label id="username-lbl" for="username" class=" required">User Name<span class="star"> *</span></label> </span>
</p>
<div class="controls">
<input type="text" name="username" id="username" value="" class="validate-username required" size="25"/> </div>
<p>
<span class="add-on">
<label id="password-lbl" for="password" class=" required">Password<span class="star"> *</span></label> </span>
</p>
<div class="controls">
<input type="password" name="password" id="password" value="" class="validate-password required" size="25"/> </div>
<div style="text-align: center; padding-top: 20px; padding-bottom: 20px;">
<button type="submit" class="btn btn-primary dummy-button" >Log in</button>
</div>
<input type="hidden" name="return" value="aW5kZXgucGhwP29wdGlvbj1jb21fdXNlcnMmdmlldz1wcm9maWxl" />
<input type="hidden" name="1132a16eb61f5659e8ff62fb935f6037" value="1" /> </fieldset>
</div>
</form>
Thanks in advance
Try this,
In the Joomla installation site , you have to create a external script(file). the access the Framework there with following code.
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
Now you will be able to use all Joomla libraries and functions on the page.
simple check your login details with following codes.
$credentials['username'] = $data['username']; //user entered name
$credentials['password'] = $data['password']; //users entered password
$app = JFactory::getApplication();
$error = $app->login($credentials, $options);
if (!JError::isError($error)) {
// login success
}
else{
//Failed attempt
}
Make sure this script is available in public access so pass any secret key to access only with your additional encrypted parameter.
Hope it helps..