Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An error message: undefined index???

Status
Not open for further replies.

800320

Technical User
May 26, 2003
14
MY
I'm using php4 and mysql which are running under apache server. But i always get a message: undefined index in "..../file/.." on line.....
What's the problem with my coding??
Please help.
 
Thank you for your help,Mike.
Here is my php code which is used for validating form.

*****ErrorPage.php******
<?php
include(&quot;file:///C|/Program%20Files/Apache%20Group/Apache/htdocs/myHome/config.php&quot;);

$username = $HTTP_POST_VARS[&quot;username&quot;];
$member_pass = $HTTP_POST_VARS[&quot;member_pass&quot;];
$confirmpass = $HTTP_POST_VARS[&quot;confirmpass&quot;];
$member_name = $HTTP_POST_VARS[&quot;member_name&quot;];
$member_add = $HTTP_POST_VARS[&quot;member_add&quot;];
$e_mail = $HTTP_POST_VARS[&quot;e_mail&quot;];
$mobile_num = $HTTP_POST_VARS[&quot;mobile_num&quot;];
$home_num = $HTTP_POST_VARS[&quot;home_num&quot;];

$error=&quot;&quot;;

if(!($username)&&!($member_pass)&&!($confirmpass)&&!($member_name)&&!($member_add)&&!($e_mail)){
$error = &quot;$error<li>No username given<BR>\n&quot;;
} else {

if(ereg(&quot;^[[:alnum:]]+$&quot;,$username)){
$username=true;
} else {
$username=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter your username.</b><br />\n&quot;;
}

if(ereg(&quot;^[[:alnum:]]{12,}$&quot;,$member_pass)){
$member_pass=true;
} else {
$member_pass=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter your password.</b><br />\n&quot; ;
}

if($member_pass==$confirmpass){
$confirmpass=true;
$member_pass=crypt($confirmpass);
} else{
$confirmpass=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Password did not match confirmed password.</b><br />\n&quot;;
}

if(eregi(&quot;^[[:alpha:]]+$&quot;,$member_name)){
$member_name=true;
} else {
$member_name=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter your name.</b><br />\n&quot;;
}
if(eregi(&quot;^([[:alnum:]]|[[:blank:]]|[[:punct:]]|[[:space:]])$&quot;,$member_add)){
$validmember_add=true;
} else {
$validmember_add=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter your address.</b><br />\n&quot;;
}
if(eregi(&quot;^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$&quot;,$e_mail)){
$e_mail=true;
} else {
$e_mail=false;
print(&quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter your e-mail.&quot;);
}
if(eregi(&quot;^([[:digit:]]{3,})+(\-)([[:digit;]]{7,0})$&quot;,$mobile_num)){
$mobile_num=true;
} else {
$mobile_num=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter mobile phone number with hyphen after 3 digit in the front.</b><br />\n&quot;;
}
if(eregi(&quot;^([[:digit:]]{2,})+(\-)([[:digit;]]{5,9})$&quot;,$home_num)){
$home_num=true;
} else {
$home_num=false;
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Please reenter phone number with hyphen after 2 digit in the front.</b><br />\n&quot;;
}
}

if($username AND $member_pass AND $confirmpass AND $member_name AND $member_add AND $e_mail==TRUE){
$query = &quot;Select username,member_pass,e_mail from members where username='$username' or member_pass='$member_pass' or e_mail='$e_mail'&quot;;
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)){
if($row[&quot;username&quot;] == $username){
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Your username is already registered in our database.</b><br />\n&quot;;
}
if($row[&quot;member_pass&quot;] == $member_pass){
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Your member password is already registered in our database.</b><br />\n&quot;;
}
if($row[&quot;e_mail&quot;] == $e_mail){
echo &quot;<div align=\&quot;left\&quot;><font color=red><b>Your e-mail is already registered in our database.</b><br />\n&quot;;
}
} else {
$query = &quot;INSERT INTO members (username, member_pass, member_name, member_add, e_mail, mobile_num ,home_num) VALUES ('$username','$member_pass','$member_name','$member_add', '$mobile_num', '$home_num')&quot;;
$result = mysql_query($query);
}
}

?>

******Register******

<form method=&quot;post&quot; action=&quot;/ErrorPage.php&quot;>
<td>Username
<input type=&quot;text&quot; name=&quot;username&quot; size=&quot;30&quot;>
<td>Password
<td><input type=&quot;password&quot; name=&quot;member_pass&quot; size=&quot;30&quot;>
<tr>Confirm Password<td><input type=&quot;password&quot; name=&quot;confirmpass&quot; size=&quot;30&quot;>
<tr><td> 
</fieldset>

<p>
<fieldset>
<em><font face=&quot;Arial, Helvetica, sans-serif&quot;>
<legend align=&quot;bottom&quot;><font color=&quot;#009900&quot; size=&quot;2&quot;><strong>Personal
Details</strong></font></legend>
</font></em><font face=&quot;Arial, Helvetica, sans-serif&quot;> </font>
<td>Name</td>
<td width=&quot;180&quot; height=&quot;25&quot;><input type=&quot;text&quot; name=&quot;member_name&quot; size=&quot;30&quot;>
<tr>
<td>Address <td><textarea name=&quot;member_add&quot; rows=&quot;6&quot; cols=&quot;20&quot;></textarea>
<tr>
<td> E-Mail
<td><input type=&quot;text&quot; name=&quot;e_mail&quot; size=&quot;30&quot;>
<tr>
<td> Mobile Phone
<td><input type=&quot;text&quot; name=&quot;mobile_num&quot; size=&quot;30&quot;>
<tr>
<td> Home Phone
<td><input type=&quot;text&quot; name=&quot;home_num&quot; size=&quot;30&quot;>
</table>
</fieldset>


<table width=&quot;400&quot; bordercolor=&quot;#FFFFFF&quot; rules=&quot;none&quot; align=&quot;center&quot;>
<tr>
<td><div align=&quot;center&quot;><a href=&quot;/ErrorPage.php&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image2','','/imageHome/btnSubD.jpg',1)&quot;><img src=&quot;/imageHome/btnSubmit.jpg&quot; name=&quot;Image2&quot; width=&quot;57&quot; height=&quot;28&quot; border=&quot;0&quot;></a></div>
<td> <div align=&quot;center&quot;><a href=&quot;#&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image3','','/imageHome/btnReD.jpg',1)&quot;><img src=&quot;/imageHome/btnreset.jpg&quot; name=&quot;Image3&quot; width=&quot;57&quot; height=&quot;28&quot; border=&quot;0&quot;></a></div>
</tr></table>
</form>
 
Jesus, what's with posting your whole code??? We only need to see the bit which is causing you them problem.

If it says there's an error on Line 5, then post lines 1-10 and someone might be able to solve the problem. If you post a huge amount of code and say it's not working, 9 times out of 10, people will glance at the stupid amount of code you've posted and forget it.

Anyways...
Code:
<?php
include(&quot;file:///C|/Program%20Files/Apache%20Group/Apache/htdocs/myHome/config.php&quot;);

should be

<?php
include(&quot;file:///C:/Program%20Files/Apache%20Group/Apache/htdocs/myHome/config.php&quot;);
[/code]

Change it, see what error's you get (if any) then post only the lines of you code are getting errors on....

Hope this helps....

 
Why do a URL include using &quot;file:&quot;? At best, it's redundant, at worst it won't work -- the PHP online documentation doesn't include &quot;file:&quot; as a wrapper. Just pass include() the name of the file on the filesystem.

What error, exactly, are you getting? And which line in that mass posting is the offending line?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Sorry for giving the messy coding. Please help.

(ERROR: -Undefined index: username in c:\program
files\apachegroup\apache\htdocs\myhome\errorpage.php on line...
-Undefined index: member_name in......... on line...
-Undefined index: confirmpass in ..........on line.
.
. )
(*In the linking page, i use those variable name as my <input name=&quot; &quot;> )

****ErrorPage.php*****
<?php

include(&quot;config.php&quot;);

$username = $HTTP_POST_VARS[&quot;username&quot;];
$member_pass = $HTTP_POST_VARS[&quot;member_pass&quot;];
$confirmpass = $HTTP_POST_VARS[&quot;confirmpass&quot;];
$error=&quot;&quot;;

if(!($username)&&!($member_pass)&&!($confirmpass)){
$error = &quot;$error<li>No username given<BR>\n&quot;;
} else {
if(ereg(&quot;^[[:alnum:]]+$&quot;,$username)){
$username=true;
} else {
$username=false;
echo &quot;Please reenter your username.&quot;;
}

if(ereg(&quot;^[[:alnum:]]{12,}$&quot;,$member_pass)){
$member_pass=true;
} else {
$member_pass=false;
echo &quot;Please reenter your password.&quot; ;
}
if($member_pass==$confirmpass){
$confirmpass=true;
$member_pass=crypt($confirmpass);
} else{
$confirmpass=false;
echo &quot;Password did not match confirmed password.&quot;;
}
.....
?>
 
Lol, you've missed out the most important bit....We need to know at which line the error occurs... and then show us the line...

Then we can start to help...
 
Do you not ave to do something like $HTTP_POST_VARS(&quot;fred&quot;) rather tha $HTTP_POST_VARS&quot;fred&quot;. Is this an odd syntax thing I've missed ??

I would also put a phpinfo() call BEFORE the error to see what is being passed into your script. But as most other posters have said try to get the smallest case that you get the error.
 
ingresman:

With PHP code, there are two workarounds:

One is to use single quotes around associative array reference indeces: $a['foo'].

The other is to post all code inside [ignore][ignore][/ignore][/ignore] or [ignore]
Code:
[/ignore] TGML tags, both of which turn off TGML processing.

If possible, do both. If not, certainly use the latter.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top