Click here to Skip to main content
14,832,124 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Notice: Undefined index: uname in C:\xampp\htdocs\phplearn\registration1.php on line 7

Notice: Undefined index: email in C:\xampp\htdocs\phplearn\registration1.php on line 8

Notice: Undefined index: pass in C:\xampp\htdocs\phplearn\registration1.php on line 9

What I have tried:

PHP
  1  <?php
  2  include('connection.php');
  3  //insert code
  4  
  5  if(isset($_REQUEST['add']))
  6  {
  7  	$u =$_REQUEST['uname'];
  8  	$e =$_REQUEST['email'];
  9  	$p =$_REQUEST['pass'];
 10  	$g =$_REQUEST['gender'];
 11  	$h =implode(",",$_REQUEST['chk']);
 12  	$c =$_REQUEST['city'];
 13  	$ad =$_REQUEST['address'];
 14  	$ins = "INSERT INTO tbl_user(uname,email,pass,gender,hobby,city,address) values ('$u','$e','$p','$g','$h','$c','$ad')";
 15  	$ex =$con->query($ins);
 16  }
 17  ?>
Posted
Updated 16-Aug-20 2:17am
v3
Comments
[no name] 16-Aug-20 7:19am
   
looks like $_REQUEST['uname'], $_REQUEST['email']and $_REQUEST['pass'] are not defined. So you need to find out why.
Richard Deeming 17-Aug-20 11:40am
   
In addition to the SQL Injection vulnerability in your code, you're storing passwords in plain text. Don't do that!

Use PHP's built-in functions to help you store and verify the password securely:
PHP: password_hash[^]
PHP: password_verify[^]
[no name] 17-Aug-20 13:29pm
   
+5 even it does not count

Quote:
Notice: Undefined index: uname in C:\xampp\htdocs\phplearn\registration1.php on line 7
Notice: Undefined index: email in C:\xampp\htdocs\phplearn\registration1.php on line 8
Notice: Undefined index: pass in C:\xampp\htdocs\phplearn\registration1.php on line 9

This means that those index do not exist in variable $_REQUEST. We have no way to know the reason. Only you can see the real contain of $_REQUEST with the help of debugger.
PHP
$ins = "INSERT INTO tbl_user(uname,email,pass,gender,hobby,city,address) values ('$u','$e','$p','$g','$h','$c','$ad')";

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[^]
   
You need to understand what this error means to solve for it. Here: Notice: Undefined Index error in PHP[^]

Quote:
This error means that within your code, there is a variable or constant that has no value assigned to it. But you may be trying to use the values obtained through the user form in your PHP code.

The error can be avoided by using the isset() function. This function will check whether the index variables are assigned a value or not, before using them.


Here, check for uname, email, pass for isset before using it. Seems your going ahead logic too depends on that so all needs to be adjusted.


UPDATE:
Some details around your code:
PHP $_REQUEST[^]
Quote:
PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.


So, until unless there is no event to raise request, it will not be set. Thus, by default first time it would not hold value and throw an error. Using isset as shared will solve that.
   
v3

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