943,925 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1076
  • PHP RSS
Mar 28th, 2008
0

small error when submitting form

Expand Post »
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>
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
sukhy_1 is offline Offline
63 posts
since Mar 2008
Mar 28th, 2008
0

Re: small error when submitting form

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
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
sagedavis is offline Offline
86 posts
since Nov 2007
Mar 29th, 2008
0

Re: small error when submitting form

OK, I'm pasting the code you IMd me here, because there are others who may be able to help with this as well.
PHP Syntax (Toggle Plain Text)
  1. <script src="signupcheck.js" language="JavaScript" type="text/javascript">
  2. </script>
  3.  
  4. <Script language = javascript>
  5.  
  6. function Validate() {
  7. Message = "";
  8.  
  9. Message = Message + Checkmyusername();
  10.  
  11. if (Message == "") {
  12. return true;
  13. }
  14. else {
  15. alert(Message)
  16. return false;
  17. }
  18.  
  19. }
  20.  
  21. function Checkmyusername() {
  22. email = document.f1.myusername.value;
  23. AtPos = email.indexOf("@");
  24. StopPos = email.lastIndexOf(".");
  25. Message = "";
  26.  
  27. if (email == "") {
  28. Message = "Not a valid Email address" + "\n";
  29. return Message;
  30. }
  31.  
  32. if (AtPos == -1 || StopPos == -1) {
  33. Message = "Not a valid email address" + "\n";
  34. return Message;
  35. }
  36.  
  37. if (StopPos < AtPos) {
  38. Message = "Not a valid email address" + "\n";
  39. return Message;
  40. }
  41.  
  42. if (StopPos - AtPos == 1) {
  43. Message = "Not a valid email address" + "\n";
  44. return Message;
  45. }
  46.  
  47. return Message;
  48. }
  49.  
  50. </script>
  51.  
  52. <form name="f1" method="post" action="Signupcomplete.php" onSubmit="return Validate()" enctype = text/plain>
  53.  
  54. <tr>
  55. <td>Fields marked with an asterisk (*) are mandatory</td>
  56. </tr>
  57.  
  58. <tr><td height=20></td></tr>
  59.  
  60. <tr>
  61. <td>Your Name*<small> (Enter First and Last Name)</small></td>
  62. <td><input type="text" name="StudentName"></td>
  63. </tr>
  64.  
  65. <tr>
  66. <td>Email Address*<small> (This will be your User Name)</small></td>
  67. <td><input type="text" name="myusername"></td>
  68. </tr>
  69.  
  70. <tr>
  71. <td>Type a password*</td>
  72. <td> <input type="password" name="mypassword" maxlength="16" value="" /></td>
  73. </tr>
  74.  
  75. <tr>
  76. <td>I accept: <input type="checkbox" value="0" name="agree">
  77. <p><input type="submit" name="Submit" value="Sign Up"></td>
  78. </tr>
  79. </td>
  80. </center>
  81. </table>
  82. </form>
  83. </body>
  84. </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
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
sagedavis is offline Offline
86 posts
since Nov 2007
Mar 29th, 2008
0

Re: small error when submitting form

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...
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
sukhy_1 is offline Offline
63 posts
since Mar 2008
Mar 29th, 2008
0

Re: small error when submitting form

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


PHP Syntax (Toggle Plain Text)
  1. $StudentName = $_POST['StudentName'];


Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 29th, 2008
0

Re: small error when submitting form

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
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
sukhy_1 is offline Offline
63 posts
since Mar 2008
Mar 29th, 2008
0

Re: small error when submitting form

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


PHP Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 29th, 2008
0

Re: small error when submitting form

php Syntax (Toggle Plain Text)
  1. <?
  2. $sql = sprintf(
  3. "INSERT INTO StudentRecords (StudentName, TelephoneNumber, DOB) ".
  4. "VALUES ('%s','%s','%s')",
  5. mysql_real_escape_string(stripslashes($_REQUEST['StudentName'])),
  6. mysql_real_escape_string(stripslashes($_REQUEST['TelephoneNumber'])),
  7. mysql_real_escape_string(stripslashes($_REQUEST['DOB']))),
  8. $result=mysql_query($sql) or die(mysql_error());
  9.  
  10. $sql= sprintf ("INSERT INTO members (password,username) VALUES ('%s','%s')",
  11. md5(stripslashes($_REQUEST['mypassword'])),
  12. mysql_real_escape_string(stripslashes($_REQUEST['myusername'])));
  13. $result=mysql_query($sql) or die(mysql_error());
  14.  
  15.  
  16. echo "You are now a member safe";mysql_close($con)
  17. ?>
Last edited by peter_budo; Mar 30th, 2008 at 6:14 am. Reason: Keep It Organized - please use [code] tags
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
sukhy_1 is offline Offline
63 posts
since Mar 2008
Mar 29th, 2008
0

Re: small error when submitting form

Thats only 17 lines

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


Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: MS Access ....
Next Thread in PHP Forum Timeline: regex/preg_match_all help needed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC