hello ive got a sign in page it works and sends data to database but soon as i had validation code for an email address using java, and then when i click submit it comes up with this error below for every textbox even though all the textboxes have data entered in them this error appears when the form is submitted... any ideas what could be causing this


Notice: Undefined index: StudentName in /home/stud/1/0472547/public_html/Signupcomplete.php on line 49

<form name="f1" method="post" action="Signupcomplete.php" onSubmit="return Validate()" enctype = text/plain>

<p><input type="submit" name="Submit" value="Sign Up"></td>

Recommended Answers

All 8 Replies

java or javascript?

It's hard to tell, since you aren't showing us your javascript.... but,...
I would say your "Validate" is somehow over riding everything.
You may be trying to pass the information from these fields via javascript to php, this isn't impossible, it's just tricky...

Your best bet is to force the validate before the submit.. for instance, most people will have to focus on the submit button so, force the running of "validate to happen onFocus of the submit button. This will ensure that if all fields aren't proper, they won't be able to click submit, but, if all is good, it will validate and they will be able to push the button..
Just a guess as I can't see your code.
Sage

OK, I'm pasting the code you IMd me here, because there are others who may be able to help with this as well.

<script src="signupcheck.js" language="JavaScript" type="text/javascript">
</script>

<Script language = javascript>

function Validate() {
Message = "";

Message = Message + Checkmyusername();

	if (Message == "") {
	return true;
	}
	else {
	alert(Message)
	return false;
	}

}

function Checkmyusername() {
email = document.f1.myusername.value;
AtPos = email.indexOf("@");
StopPos = email.lastIndexOf(".");
Message = "";

	if (email == "") {
	Message = "Not a valid Email address" + "\n";
	return Message;
	}

	if (AtPos == -1 || StopPos == -1) {
	Message = "Not a valid email address" + "\n";
	return Message;
	}

	if (StopPos < AtPos) {
	Message = "Not a valid email address" + "\n";
	return Message;
	}

	if (StopPos - AtPos == 1) {
	Message = "Not a valid email address" + "\n";
	return Message;
	} 

return Message;
}

</script>

<form name="f1" method="post" action="Signupcomplete.php" onSubmit="return Validate()" enctype = text/plain>

<tr>
<td>Fields marked with an asterisk (*) are mandatory</td>
</tr>

<tr><td height=20></td></tr>

<tr>
<td>Your Name*<small> (Enter First and Last Name)</small></td>
<td><input type="text" name="StudentName"></td>
</tr>

<tr>
<td>Email Address*<small> (This will be your User Name)</small></td>
<td><input type="text" name="myusername"></td>
</tr>

<tr>
<td>Type a password*</td>
<td> <input type="password" name="mypassword" maxlength="16" value="" /></td>
</tr> 

<tr>
<td>I accept: <input type="checkbox" value="0" name="agree">
<p><input type="submit" name="Submit" value="Sign Up"></td>
</tr>
</td>
</center>
</table>
</form>
</body>
</html>

Some ideas here... The function that you really want to call is CheckMyUsername because Validate is not really pushing the information that you want it to, and you can handle everything within the CheckMyUsername function anyway. This, I believe is where your code is breaking.

after each line you need a ";" I have added these in your code above for you. To be honest, this depends on what browser you are using.. IE7 doesn't care about this, but it is still good practice regardless.

I believe (if I am not mistaken) that your variables need to be declared as such... so,
where you have variables you need to type
var foo = "bar";

one thing that you should do after each step run an alert just to see where you are breaking...

I also think you need to put the function call on the button itself and make it an on focus event, or onmousedown that triggers the function call and not onsubmit.

Hope this helps
Sage

hello still dont work but ive noticed the data still gets input to the database but that notice keeps appearing the only data that dont get entered is the username because its got javascript dont understand what the problem could be...

The error is in your PHP. You are missing this:

$StudentName = $_POST['StudentName'];

Matti Ressler
Suomedia

but ive got that code in my php, when i take the vaildation off for email everything works, its just when i add that javascript the notices come up cheers

This is a PHP error, not a javascript error. Your error message tells EXACTLY where the problem is:

Notice: Undefined index: StudentName in /home/stud/1/0472547/public_html/Signupcomplete.php on line 49

Line 49. Please post the code in this file.


Matti Ressler
Suomedia

<?
$sql = sprintf(
  "INSERT INTO StudentRecords (StudentName, TelephoneNumber, DOB) ".
  "VALUES ('%s','%s','%s')",
  mysql_real_escape_string(stripslashes($_REQUEST['StudentName'])),
 mysql_real_escape_string(stripslashes($_REQUEST['TelephoneNumber'])),
  mysql_real_escape_string(stripslashes($_REQUEST['DOB']))),
  $result=mysql_query($sql) or die(mysql_error());

$sql= sprintf ("INSERT INTO members (password,username) VALUES ('%s','%s')",
  md5(stripslashes($_REQUEST['mypassword'])),
  mysql_real_escape_string(stripslashes($_REQUEST['myusername'])));
  $result=mysql_query($sql) or die(mysql_error());

 
echo "You are now a member safe";mysql_close($con)
?>

Thats only 17 lines :icon_frown:

How about attaching the actual whole file? - Signupcomplete.php


Matti Ressler
Suomedia

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.