0

my code gives undefine index error .. and i don't know how to solve it...
i m making online testing program but every eror in every step is undefine index error...
ok my html file is

<html>
<form action = "http://localhost/onlineexam/home.php" method = 'get'>


<center><h1>WELCOME TO ONLINE EXAMINATION</h1>
<br>


<br> User Name    <input type = 'text' name='username'>
<br> Enrolled no <input type = 'text' 

name='enrollno'>


<br>  <input type ='submit' value='Login' >


</form></center>
</body>
</html>

and my php code is 

<?php

$u1=$_GET['username'];
$e1=$_GET['enrollno'];


$ip='localhost';
$user='root';
$pass='';
$con = mysql_connect($ip,$user,$pass);
if(!($con))
die("connection fail");
$db=mysql_select_db('onlinetesting');
if(!($db))
die("<br>database not found");
$querry="select *from login where u_name='$u1',enrolled_no='e1'";
$result= mysql_query($querry);
if($result)
echo("<html>


<center>
<h1> WELCOME $u1</h1>
<h2> CLICK FOR THE TEST START</h2>
 <form action='http://localhost/onlineexam/test.php' method='get'>

   <input type='hidden' name='id' value='1'>

   <input type='submit'  value='Start'>



</form>
</center>

</html>
");
else
echo("SORRY $u1 REGISTERED FIRST<br><a href='registration.html'>CLICK HERE</a>");
?>

but it gives the error

Notice: Undefined index: username in M:xampphtdocsonlineexamhome.php on line 3
[this line was $u1=$_GET['username']

Notice: Undefined index: enrollno in M:xampphtdocsonlineexamhome.php on line 4

[this line was $e1=$_GET['enrollno'];
SORRY REGISTERED FIRST
CLICK HERE

Edited by diafol: Use code tags

3
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by Misbah khan
0

Well, straight forward I can see something very wrong with your code: you didn't define any <head> tags, and you closed the <body> tag without opening it.

About the error, I just tried that exact same code and I had no problem. The only way that should give you trouble is if you try to access the home.php by itself, not through the form.

0

You get that notice because the GET array does not always contain that value. You can solve it by doing something like this:

$u1 = isset($_GET['username']) ? $_GET['username'] : '';
$e1 = isset($_GET['enrollno']) ? $_GET['enrollno'] : 0;

This way they always get a default value.

0

$u1 = isset($_GET['username']) ? $_GET['username'] : '';
$e1 = isset($_GET['enrollno']) ? $_GET['enrollno'] : 0;

great...my this arary problum is solve.. but can u plzz explne how its work what u wrt... and one prob is again ... come afetr registration.. the enrollnum and then user name not matched bcz its always give else output ..means registered first.. although i come after registation ..

$querry="select *from login where u_name='$u1',enrolled_no='e1'";

this is the query it has no problum but why its give again else value..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.