Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Anytime I Open My Page I Encounter This Error.

Undefined index: mobile in C:\xampp\htdocs\Church\views\CreateAccount.php on line 4

What I have tried:

<?php
include '../dbcon.php';
session_start();
$mobile = mysqli_real_escape_string($con, $_SESSION['mobile']);
$result =@mysqli_query($con,"SELECT memberid FROM members WHERE mobilenumber='$mobile'");
$id = '';
while ($row = mysqli_fetch_array($result)){
$id = $row["memberid"];
}
?>




<title>Create Account





New User Id



New Password



Confirm Password



<?php
if(isset($_POST['create'])) {
$username = mysqli_real_escape_string($con, $_POST['userid']);
$pwd = mysqli_real_escape_string($con, $_POST['pwd']);
$role = "member";
$query = "INSERT INTO accounts(username,memberid,password,role) values('$username',$id,'$pwd','$role')";
if (mysqli_query($con, $query)) {
header("Location:../Login.php");
} else {
echo '$(\'#alert\').html(\'<div class="alert alert-danger alert-dismissible">An Error Occured Please Try Again Or Username Already Exists</div>\'); ';
}
}
?>


function Validate() {
var pwd = document.getElementById('pwd').value;
var cpwd = document.getElementById('cpwd').value;
if(pwd != cpwd)
{
var a = $('#alert').html('<div class="alert alert-danger alert-dismissible">Password MisMatch</div>');
$('#pwd').focus();
setInterval(function(){
$('#alert').html('');
}, 3000);
$('#frm').submit(function (e) {
e.preventDefault();
return false;
})
}
else
{
$('#frm').submit(function (ev) {
ev.submit();
})
}
}
Posted
Updated 25-Jul-18 7:23am
Comments
ZurdoDev 25-Jul-18 12:41pm    
1. Please update your title to something relevant.
2. I don't do php but it would seem that $_SESSION['mobile'] is not set.
Richard MacCutchan 25-Jul-18 13:22pm    
There is no item in the HTML or session table with the name 'mobile'.
Richard MacCutchan 25-Jul-18 13:23pm    
You do realise that storing passwords in clear text is a massive security hole in your system.
Richard Deeming 25-Jul-18 13:42pm    
Well, it's not like PHP has any built-in methods to help you do the right thing, is it?

Oh, wait:
PHP: password_hash[^]
PHP: password_verify[^]

:)

1 solution

Use the debugger to make sure that $_SESSION['mobile'] exist.

PHP
$query = "INSERT INTO accounts(username,memberid,password,role) values('$username',$id,'$pwd','$role')";

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900