Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am getting the following errors in my php code
Notice: Undefined index: name in C:\wamp\www\simplifiedcodding\register.php on line 3
Notice: Undefined index: name in C:\wamp\www\simplifiedcodding\register.php on line 4
Notice: Undefined index: name in C:\wamp\www\simplifiedcodding\register.php on line 5
Notice: Undefined index: name in C:\wamp\www\simplifiedcodding\register.php on line 6
see my php code below

PHP
<?php
 
 $name = $_GET['name'];
 $username = $_GET['username'];
 $password = $_GET['password'];
 $email = $_GET['email'];
 
 if($name == '' || $username == '' || $password == '' || $email == ''){
 echo 'please fill all values';
 }else{
 require_once('dbConnect.php');
 $sql = "SELECT * FROM users WHERE username='$username' OR email='$email'";
 
 $check = mysqli_fetch_array(mysqli_query($con,$sql));
 
 if(isset($check)){
 echo 'username or email already exist';
 }else{ 
 $sql = "INSERT INTO users (name,username,password,email) VALUES('$name','$username','$password','$email')";
 if(mysqli_query($con,$sql)){
 echo 'successfully registered';
 }else{
 echo 'oops! Please try again!';
 }
 }
 mysqli_close($con);
 }
 
 ?>

Kindly help


What I have tried:

I have tried googling it but have not found the right answer
Posted
Comments
Sinisa Hajnal 11-Feb-16 3:08am    
Not PHP expert by any means, but the error says this is undefined: $name = $_GET['name']; -> so...define it before use? If you remove that line, I'm betting you would get undefined index username.
Richard MacCutchan 11-Feb-16 4:28am    
Did you try checking why those names are not defined in your webpage?

1 solution

The data in the $_GET array is passed in from an outside call - but not always - as they may, instead be passed via $_POST. If you send them one way and ask for them the other, they'll not be found.   Easiest solution: use $_REQUEST, which will read both types (also good if you change your method of passing data at some time, such as if it gets really large or have greater security needs).

That's an easy first try - if you're actually sending the data!

If you're not sure about that, see: THIS[^]



 
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