Jump to content

Strange undefined index error


bugzy

Recommended Posts

Ok I have this code..

 

 

<?php

header("Expires: Thu, 17 May 2001 10:17:17 GMT");    // Date in the past
  	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");                          // HTTP/1.0

session_start();

if (!isset($_SESSION['SESSION'])) require ( "../db_connection.php");


?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Registration Form</title>
</head>

<body><center><br /><br />

<form name="registration" method="post" action="/php/user_registration/registered.php">
<table>

<tr>
    	<td>First Name:</td>
        <td><input type="text" name="fname" value="<?php $_SESSION['fname'] ?>" size="30" maxlength="50" /></td>
    </tr>
    
    <tr>
    	<td>Last Name:</td>
        <td><input type="text" name="lname" value="<?php $_SESSION['lname'] ?>" size="30" maxlength="50" /></td>
    </tr>
    
    <tr>
    	<td>E-Mail Address:</td>
        <td><input type="text" name="email" value="<?php $_SESSION['email'] ?>" size="30" maxlength="50" /></td>
    </tr>
    
    <tr>
    	<td>Phone:</td>
        <td><input type="text" name="phone" value="<?php $_SESSION['phone'] ?>" size="30" maxlength="50" /></td>
    </tr>
    
    
    <tr>
    	<td>City:</td>
        <td><input type="text" name="city" value="<?php $_SESSION['city'] ?>" size="30" maxlength="50" /></td>
    </tr>
    
   
    
   
    
    <tr>
    	<td>Status:</td>
        <td>
        <select name="status" id="status">
        <option>Pls. Select One
        <option value="single">Single
        <option value="relationship">In a Relationship
        <option value="complicated">It's Complicated     
        </select>
        </td>
    </tr>
    
    
     <tr>
    	<td>Province:</td>
        <td><input type="text" name="province" value="<?php $_SESSION['province'] ?>" size="30" maxlength="50" /></td>
    </tr>
    

    
    <tr>
    	<td>Password:</td>
        <td><input type="password" name="password" size="30" maxlength="50" /></td>
    </tr>
    
    <tr>
    	<td>Confirm Password:</td>
        <td><input type="password" name="password2" size="30" maxlength="50" /></td>
    </tr>
    
    <tr>
    	<td>            <input type="reset" name="Submit2" value="Reset"></td>
        <td>            <input type="button" name="Submit" value="Submit" onclick="SubmitForm();  return false;" ></td>
    </tr>



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

 

 

I'm not actually doing anything yet up there though I'm having an error on row "province". The error is

 

Undefined index: province in C:\wamp\www\php\user_registration\registration_form.php on line 75

 

 

I have tried almost everything and of all the rows I have there, that's the only one I'm having error at. I'm curious why I'm getting that error.

 

Anyone?

Link to comment
https://forums.phpfreaks.com/topic/259974-strange-undefined-index-error/
Share on other sites

It's probably giving you the error because it hasn't been initialized. I have no idea why it wouldn't ding you on the previous session variables. And of note, those variables aren't actually doing anything. If you want them to print out the actual values in those variables, you need to put echo before them.

 

Hey like what I said.. those code aren't doing anything yet.. It just so happened that when I try to look at it on the page I see that error and I'm just curious why of all the row I have there that's the only row that is giving me that error..

Because the variable isn't defined. Even though you aren't printing it out, the server is still trying to access it. If you set the variable (i.e. $_SESSION['province'] = 'none';) then it will see that it is initialized and give you an error for the next one up ($_SESSION['city']), and so on until you have actually initialized all of them.

Because the variable isn't defined. Even though you aren't printing it out, the server is still trying to access it. If you set the variable (i.e. $_SESSION['province'] = 'none';) then it will see that it is initialized and give you an error for the next one up ($_SESSION['city']), and so on until you have actually initialized all of them.

 

 

Ok I have initialized it and it echoes out the value though the city row doesn't have any error at all. I even tried removing the province row to see if I will get an error on the next one up which is the city or any other row but I got no errors at all.

 

Sorry I'm just new in php and I find it strange.

It could be that you have defined it elsewhere, since it is, after all, a session variable. I plugged in your code to my box and I got an error for all of them, including city. Try setting a default value for all the variables and see if that works.

 

 

Hey I tried to destroy the session and after that all the rows are getting an error now. You are correct maybe I have defined it somewhere else.

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.