By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

registration form

P: 3
*************error***************

( ! ) Notice: Undefined index: doRegister in C:\wamp\www\register.php on line 21

( ! ) Notice: Undefined index: recaptcha_challenge_field in C:\wamp\www\register.php on line 38

( ! ) Notice: Undefined index: recaptcha_response_field in C:\wamp\www\register.php on line 39

*************end of error********************
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3. include 'dbc.php';
  4.  
  5. $err = array();
  6.  
  7. if($_POST['doRegister'] == 'Register') 
  8. /******************* Filtering/Sanitizing Input *****************************
  9. This code filters harmful script code and escapes data of all POST data
  10. from the user submitted form.
  11. *****************************************************************/
  12. foreach($_POST as $key => $value) {
  13.     $data[$key] = filter($value);
  14. }
  15.  
  16. /********************* RECAPTCHA CHECK *******************************
  17. This code checks and validates recaptcha
  18. ****************************************************************/
  19.  require_once('recaptchalib.php');
  20.  
  21.       $resp = recaptcha_check_answer ($privatekey,
  22.                                       $_SERVER["REMOTE_ADDR"],
  23.                                       $_POST["recaptcha_challenge_field"],
  24.                                       $_POST["recaptcha_response_field"]);
  25.  
  26.       if (!$resp->is_valid) {
  27.         die ("<h3>Image Verification failed!. Go back and try again.</h3>" .
  28.              "(reCAPTCHA said: " . $resp->error . ")");            
  29.       }
  30. /************************ SERVER SIDE VALIDATION **************************************/
  31. /********** This validation is useful if javascript is disabled in the browswer ***/
  32.  
  33. if(empty($data['full_name']) || strlen($data['full_name']) < 4)
  34. {
  35. $err[] = "ERROR - Invalid name. Please enter atleast 3 or more characters for your name";
  36. //header("Location: register.php?msg=$err");
  37. //exit();
  38. }
  39.  
  40. // Validate User Name
  41. if (!isUserID($data['user_name'])) {
  42. $err[] = "ERROR - Invalid user name. It can contain alphabet, number and underscore.";
  43. //header("Location: register.php?msg=$err");
  44. //exit();
  45. }
  46.  
  47. // Validate Email
  48. if(!isEmail($data['usr_email'])) {
  49. $err[] = "ERROR - Invalid email address.";
  50. //header("Location: register.php?msg=$err");
  51. //exit();
  52. }
  53. // Check User Passwords
  54. if (!checkPwd($data['pwd'],$data['pwd2'])) {
  55. $err[] = "ERROR - Invalid Password or mismatch. Enter 5 chars or more";
  56. //header("Location: register.php?msg=$err");
  57. //exit();
  58. }
  59.  
  60. $user_ip = $_SERVER['REMOTE_ADDR'];
  61.  
  62. // stores sha1 of password
  63. $sha1pass = PwdHash($data['pwd']);
  64.  
  65. // Automatically collects the hostname or domain  like example.com) 
  66. $host  = $_SERVER['HTTP_HOST'];
  67. $host_upper = strtoupper($host);
  68. $path   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
  69.  
  70. // Generates activation code simple 4 digit number
  71. $activ_code = rand(1000,9999);
  72.  
  73. $usr_email = $data['usr_email'];
  74. $user_name = $data['user_name'];
  75.  
  76. /************ USER EMAIL CHECK ************************************
  77. This code does a second check on the server side if the email already exists. It 
  78. queries the database and if it has any existing email it throws user email already exists
  79. *******************************************************************/
  80.  
  81. $rs_duplicate = mysql_query("select count(*) as total from users where user_email='$usr_email' OR user_name='$user_name'") or die(mysql_error());
  82. list($total) = mysql_fetch_row($rs_duplicate);
  83.  
  84. if ($total > 0)
  85. {
  86. $err[] = "ERROR - The username/email already exists. Please try again with different username and email.";
  87. //header("Location: register.php?msg=$err");
  88. //exit();
  89. }
  90. /***************************************************************************/
  91.  
  92. if(empty($err)) {
  93.  
  94. $sql_insert = "INSERT into `users`
  95.               (`full_name`,`user_email`,`pwd`,`address`,`tel`,`fax`,`website`,`date`,`users_ip`,`activation_code`,`country`,`user_name`
  96.             )
  97.             VALUES
  98.             ('$data[full_name]','$usr_email','$sha1pass','$data[address]','$data[tel]','$data[fax]','$data[web]'
  99.             ,now(),'$user_ip','$activ_code','$data[country]','$user_name'
  100.             )
  101.             ";
  102.  
  103. mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
  104. $user_id = mysql_insert_id($link);  
  105. $md5_id = md5($user_id);
  106. mysql_query("update users set md5_id='$md5_id' where id='$user_id'");
  107. //    echo "<h3>Thank You</h3> We received your submission.";
  108.  
  109. if($user_registration)  {
  110. $a_link = "
  111. *****ACTIVATION LINK*****\n
  112. http://$host$path/activate.php?user=$md5_id&activ_code=$activ_code
  113. "; 
  114. } else {
  115. $a_link = 
  116. "Your account is *PENDING APPROVAL* and will be soon activated the administrator.
  117. ";
  118. }
  119.  
  120. $message = 
  121. "Hello \n
  122. Thank you for registering with us. Here are your login details...\n
  123.  
  124. User ID: $user_name
  125. Email: $usr_email \n 
  126. Passwd: $data[pwd] \n
  127.  
  128. $a_link
  129.  
  130. Thank You
  131.  
  132. Administrator
  133. $host_upper
  134. ______________________________________________________
  135. THIS IS AN AUTOMATED RESPONSE. 
  136. ***DO NOT RESPOND TO THIS EMAIL****
  137. ";
  138.  
  139.     mail($usr_email, "Login Details", $message,
  140.     "From: \"Member Registration\" <auto-reply@$host>\r\n" .
  141.      "X-Mailer: PHP/" . phpversion());
  142.  
  143.   header("Location: thankyou.php");  
  144.   exit();
  145.  
  146.      } 
  147.  }                     
  148.  
  149. ?>
  150. <html>
  151. <head>
  152. <title>PHP Login :: Free Registration/Signup Form</title>
  153. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  154. <script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
  155. <script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
  156.  
  157.   <script>
  158.   $(document).ready(function(){
  159.     $.validator.addMethod("username", function(value, element) {
  160.         return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
  161.     }, "Username must contain only letters, numbers, or underscore.");
  162.  
  163.     $("#regForm").validate();
  164.   });
  165.   </script>
  166.  
  167. <link href="styles.css" rel="stylesheet" type="text/css">
  168. </head>
  169.  
  170. <body>
  171. <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
  172.   <tr> 
  173.     <td colspan="3">&nbsp;</td>
  174.   </tr>
  175.   <tr> 
  176.     <td width="160" valign="top"><p>&nbsp;</p>
  177.       <p>&nbsp; </p>
  178.       <p>&nbsp;</p>
  179.       <p>&nbsp;</p>
  180.       <p>&nbsp;</p></td>
  181.     <td width="732" valign="top"><p>
  182.     <?php 
  183.      if (isset($_GET['done'])) { ?>
  184.       <h2>Thank you</h2> Your registration is now complete and you can <a href="login.php">login here</a>";
  185.      <?php exit();
  186.       }
  187.     ?></p>
  188.       <h3 class="titlehdr">Free Registration / Signup</h3>
  189.       <p>Please register a free account, before you can start posting your ads. 
  190.         Registration is quick and free! Please note that fields marked <span class="required">*</span> 
  191.         are required.</p>
  192.      <?php    
  193.      if(!empty($err))  {
  194.        echo "<div class=\"msg\">";
  195.       foreach ($err as $e) {
  196.         echo "* $e <br>";
  197.         }
  198.       echo "</div>";    
  199.        }
  200.      ?> 
  201.  
  202.       <br>
  203.       <form action="register.php" method="post" name="regForm" id="regForm" >
  204.         <table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
  205.           <tr> 
  206.             <td colspan="2">Your Name / Company Name<span class="required"><font color="#CC0000">*</font></span><br> 
  207.               <input name="full_name" type="text" id="full_name" size="40" class="required"></td>
  208.           </tr>
  209.           <tr> 
  210.             <td colspan="2">&nbsp;</td>
  211.           </tr>
  212.           <tr> 
  213.             <td colspan="2">Contact Address (with ZIP)<span class="required"><font color="#CC0000">*</font></span><br> 
  214.               <textarea name="address" cols="40" rows="4" id="address" class="required"></textarea> 
  215.               <span class="example">VALID CONTACT DETAILS</span> </td>
  216.           </tr>
  217.           <tr> 
  218.             <td>Country <font color="#CC0000">*</font></span></td>
  219.             <td><select name="country" class="required" id="select8">
  220.                 <option value="" selected></option>
  221.                 <option value="Afghanistan">Afghanistan</option>
  222.                 <option value="Albania">Albania</option>
  223.                 <option value="Algeria">Algeria</option>
  224.                 <option value="Andorra">Andorra</option>
  225.                 <option value="Anguila">Anguila</option>
  226.                 <option value="Antarctica">Antarctica</option>
  227.                 <option value="Antigua and Barbuda">Antigua and Barbuda</option>
  228.                 <option value="Argentina">Argentina</option>
  229.                 <option value="Armenia ">Armenia </option>
  230.                 <option value="Aruba">Aruba</option>
  231.                 <option value="Australia">Australia</option>
  232.                 <option value="Austria">Austria</option>
  233.                 <option value="Azerbaidjan">Azerbaidjan</option>
  234.                 <option value="Bahamas">Bahamas</option>
  235.                 <option value="Bahrain">Bahrain</option>
  236.                 <option value="Bangladesh">Bangladesh</option>
  237.                 <option value="Barbados">Barbados</option>
  238.                 <option value="Belarus">Belarus</option>
  239.                 <option value="Belgium">Belgium</option>
  240.                 <option value="Belize">Belize</option>
  241.                 <option value="Bermuda">Bermuda</option>
  242.                 <option value="Bhutan">Bhutan</option>
  243.                 <option value="Bolivia">Bolivia</option>
  244.                 <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
  245.                 <option value="Brazil">Brazil</option>
  246.                 <option value="Brunei">Brunei</option>
  247.                 <option value="Bulgaria">Bulgaria</option>
  248.                 <option value="Cambodia">Cambodia</option>
  249.                 <option value="Canada">Canada</option>
  250.                 <option value="Cape Verde">Cape Verde</option>
  251.                 <option value="Cayman Islands">Cayman Islands</option>
  252.                 <option value="Chile">Chile</option>
  253.                 <option value="China">China</option>
  254.                 <option value="Christmans Islands">Christmans Islands</option>
  255.                 <option value="Cocos Island">Cocos Island</option>
  256.                 <option value="Colombia">Colombia</option>
  257.                 <option value="Cook Islands">Cook Islands</option>
  258.                 <option value="Costa Rica">Costa Rica</option>
  259.                 <option value="Croatia">Croatia</option>
  260.                 <option value="Cuba">Cuba</option>
  261.                 <option value="Cyprus">Cyprus</option>
  262.                 <option value="Czech Republic">Czech Republic</option>
  263.                 <option value="Denmark">Denmark</option>
  264.                 <option value="Dominica">Dominica</option>
  265.                 <option value="Dominican Republic">Dominican Republic</option>
  266.                 <option value="Ecuador">Ecuador</option>
  267.                 <option value="Egypt">Egypt</option>
  268.                 <option value="El Salvador">El Salvador</option>
  269.                 <option value="Estonia">Estonia</option>
  270.                 <option value="Falkland Islands">Falkland Islands</option>
  271.                 <option value="Faroe Islands">Faroe Islands</option>
  272.                 <option value="Fiji">Fiji</option>
  273.                 <option value="Finland">Finland</option>
  274.                 <option value="France">France</option>
  275.                 <option value="French Guyana">French Guyana</option>
  276.                 <option value="French Polynesia">French Polynesia</option>
  277.                 <option value="Gabon">Gabon</option>
  278.                 <option value="Germany">Germany</option>
  279.                 <option value="Gibraltar">Gibraltar</option>
  280.                 <option value="Georgia">Georgia</option>
  281.                 <option value="Greece">Greece</option>
  282.                 <option value="Greenland">Greenland</option>
  283.                 <option value="Grenada">Grenada</option>
  284.                 <option value="Guadeloupe">Guadeloupe</option>
  285.                 <option value="Guatemala">Guatemala</option>
  286.                 <option value="Guinea-Bissau">Guinea-Bissau</option>
  287.                 <option value="Guinea">Guinea</option>
  288.                 <option value="Haiti">Haiti</option>
  289.                 <option value="Honduras">Honduras</option>
  290.                 <option value="Hong Kong">Hong Kong</option>
  291.                 <option value="Hungary">Hungary</option>
  292.                 <option value="Iceland">Iceland</option>
  293.                 <option value="India">India</option>
  294.                 <option value="Indonesia">Indonesia</option>
  295.                 <option value="Ireland">Ireland</option>
  296.                 <option value="Israel">Israel</option>
  297.                 <option value="Italy">Italy</option>
  298.                 <option value="Jamaica">Jamaica</option>
  299.                 <option value="Japan">Japan</option>
  300.                 <option value="Jordan">Jordan</option>
  301.                 <option value="Kazakhstan">Kazakhstan</option>
  302.                 <option value="Kenya">Kenya</option>
  303.                 <option value="Kiribati ">Kiribati </option>
  304.                 <option value="Kuwait">Kuwait</option>
  305.                 <option value="Kyrgyzstan">Kyrgyzstan</option>
  306.                 <option value="Lao People's Democratic Republic">Lao People's 
  307.                 Democratic Republic</option>
  308.                 <option value="Latvia">Latvia</option>
  309.                 <option value="Lebanon">Lebanon</option>
  310.                 <option value="Liechtenstein">Liechtenstein</option>
  311.                 <option value="Lithuania">Lithuania</option>
  312.                 <option value="Luxembourg">Luxembourg</option>
  313.                 <option value="Macedonia">Macedonia</option>
  314.                 <option value="Madagascar">Madagascar</option>
  315.                 <option value="Malawi">Malawi</option>
  316.                 <option value="Malaysia ">Malaysia </option>
  317.                 <option value="Maldives">Maldives</option>
  318.                 <option value="Mali">Mali</option>
  319.                 <option value="Malta">Malta</option>
  320.                 <option value="Marocco">Marocco</option>
  321.                 <option value="Marshall Islands">Marshall Islands</option>
  322.                 <option value="Mauritania">Mauritania</option>
  323.                 <option value="Mauritius">Mauritius</option>
  324.                 <option value="Mexico">Mexico</option>
  325.                 <option value="Micronesia">Micronesia</option>
  326.                 <option value="Moldavia">Moldavia</option>
  327.                 <option value="Monaco">Monaco</option>
  328.                 <option value="Mongolia">Mongolia</option>
  329.                 <option value="Myanmar">Myanmar</option>
  330.                 <option value="Nauru">Nauru</option>
  331.                 <option value="Nepal">Nepal</option>
  332.                 <option value="Netherlands Antilles">Netherlands Antilles</option>
  333.                 <option value="Netherlands">Netherlands</option>
  334.                 <option value="New Zealand">New Zealand</option>
  335.                 <option value="Niue">Niue</option>
  336.                 <option value="North Korea">North Korea</option>
  337.                 <option value="Norway">Norway</option>
  338.                 <option value="Oman">Oman</option>
  339.                 <option value="Pakistan">Pakistan</option>
  340.                 <option value="Palau">Palau</option>
  341.                 <option value="Panama">Panama</option>
  342.                 <option value="Papua New Guinea">Papua New Guinea</option>
  343.                 <option value="Paraguay">Paraguay</option>
  344.                 <option value="Peru ">Peru </option>
  345.                 <option value="Philippines">Philippines</option>
  346.                 <option value="Poland">Poland</option>
  347.                 <option value="Portugal ">Portugal </option>
  348.                 <option value="Puerto Rico">Puerto Rico</option>
  349.                 <option value="Qatar">Qatar</option>
  350.                 <option value="Republic of Korea Reunion">Republic of Korea Reunion</option>
  351.                 <option value="Romania">Romania</option>
  352.                 <option value="Russia">Russia</option>
  353.                 <option value="Saint Helena">Saint Helena</option>
  354.                 <option value="Saint kitts and nevis">Saint kitts and nevis</option>
  355.                 <option value="Saint Lucia">Saint Lucia</option>
  356.                 <option value="Samoa">Samoa</option>
  357.                 <option value="San Marino">San Marino</option>
  358.                 <option value="Saudi Arabia">Saudi Arabia</option>
  359.                 <option value="Seychelles">Seychelles</option>
  360.                 <option value="Singapore">Singapore</option>
  361.                 <option value="Slovakia">Slovakia</option>
  362.                 <option value="Slovenia">Slovenia</option>
  363.                 <option value="Solomon Islands">Solomon Islands</option>
  364.                 <option value="South Africa">South Africa</option>
  365.                 <option value="Spain">Spain</option>
  366.                 <option value="Sri Lanka">Sri Lanka</option>
  367.                 <option value="St.Pierre and Miquelon">St.Pierre and Miquelon</option>
  368.                 <option value="St.Vincent and the Grenadines">St.Vincent and the 
  369.                 Grenadines</option>
  370.                 <option value="Sweden">Sweden</option>
  371.                 <option value="Switzerland">Switzerland</option>
  372.                 <option value="Syria">Syria</option>
  373.                 <option value="Taiwan ">Taiwan </option>
  374.                 <option value="Tajikistan">Tajikistan</option>
  375.                 <option value="Thailand">Thailand</option>
  376.                 <option value="Trinidad and Tobago">Trinidad and Tobago</option>
  377.                 <option value="Turkey">Turkey</option>
  378.                 <option value="Turkmenistan">Turkmenistan</option>
  379.                 <option value="Turks and Caicos Islands">Turks and Caicos Islands</option>
  380.                 <option value="Ukraine">Ukraine</option>
  381.                 <option value="UAE">UAE</option>
  382.                 <option value="UK">UK</option>
  383.                 <option value="USA">USA</option>
  384.                 <option value="Uruguay">Uruguay</option>
  385.                 <option value="Uzbekistan">Uzbekistan</option>
  386.                 <option value="Vanuatu">Vanuatu</option>
  387.                 <option value="Vatican City">Vatican City</option>
  388.                 <option value="Vietnam">Vietnam</option>
  389.                 <option value="Virgin Islands (GB)">Virgin Islands (GB)</option>
  390.                 <option value="Virgin Islands (U.S.) ">Virgin Islands (U.S.) </option>
  391.                 <option value="Wallis and Futuna Islands">Wallis and Futuna Islands</option>
  392.                 <option value="Yemen">Yemen</option>
  393.                 <option value="Yugoslavia">Yugoslavia</option>
  394.               </select></td>
  395.           </tr>
  396.           <tr> 
  397.             <td>Phone<span class="required"><font color="#CC0000">*</font></span> 
  398.             </td>
  399.             <td><input name="tel" type="text" id="tel" class="required"></td>
  400.           </tr>
  401.           <tr> 
  402.             <td>Fax </td>
  403.             <td><input name="fax" type="text" id="fax">
  404.             </td>
  405.           </tr>
  406.           <tr> 
  407.             <td>Website </td>
  408.             <td><input name="web" type="text" id="web" class="optional defaultInvalid url"> 
  409.               <span class="example">http://www.example.com</span></td>
  410.           </tr>
  411.           <tr> 
  412.             <td colspan="2">&nbsp;</td>
  413.           </tr>
  414.           <tr> 
  415.             <td colspan="2"><h4><strong>Login Details</strong></h4></td>
  416.           </tr>
  417.           <tr> 
  418.             <td>Username<span class="required"><font color="#CC0000">*</font></span></td>
  419.             <td><input name="user_name" type="text" id="user_name" class="required username" minlength="5" > 
  420.               <input name="btnAvailable" type="button" id="btnAvailable" 
  421.               onclick='$("#checkid").html("Please wait..."); $.get("checkuser.php",{ cmd: "check", user: $("#user_name").val() } ,function(data){  $("#checkid").html(data); });'
  422.               value="Check Availability"> 
  423.                 <span style="color:red; font: bold 12px verdana; " id="checkid" ></span> 
  424.             </td>
  425.           </tr>
  426.           <tr> 
  427.             <td>Your Email<span class="required"><font color="#CC0000">*</font></span> 
  428.             </td>
  429.             <td><input name="usr_email" type="text" id="usr_email3" class="required email"> 
  430.               <span class="example">** Valid email please..</span></td>
  431.           </tr>
  432.           <tr> 
  433.             <td>Password<span class="required"><font color="#CC0000">*</font></span> 
  434.             </td>
  435.             <td><input name="pwd" type="password" class="required password" minlength="5" id="pwd"> 
  436.               <span class="example">** 5 chars minimum..</span></td>
  437.           </tr>
  438.           <tr> 
  439.             <td>Retype Password<span class="required"><font color="#CC0000">*</font></span> 
  440.             </td>
  441.             <td><input name="pwd2"  id="pwd2" class="required password" type="password" minlength="5" equalto="#pwd"></td>
  442.           </tr>
  443.           <tr> 
  444.             <td colspan="2">&nbsp;</td>
  445.           </tr>
  446.           <tr> 
  447.             <td width="22%"><strong>Image Verification </strong></td>
  448.             <td width="78%"> 
  449.               <?php 
  450.             require_once('recaptchalib.php');
  451.  
  452.                 echo recaptcha_get_html($publickey);
  453.             ?>
  454.             </td>
  455.           </tr>
  456.         </table>
  457.         <p align="center">
  458.           <input name="doRegister" type="submit" id="doRegister" value="Register">
  459.         </p>
  460.       </form>
  461.       <p align="right"><span style="font: normal 9px verdana">Powered by <a href="http://php-login-script.com">PHP 
  462.                   Login Script v2.0</a></span></p>
  463.  
  464.       </td>
  465.     <td width="196" valign="top">&nbsp;</td>
  466.   </tr>
  467.   <tr> 
  468.     <td colspan="3">&nbsp;</td>
  469.   </tr>
  470. </table>
  471.  
  472. </body>
  473. </html>
  474.  
Mar 8 '12 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,059
The error message is self explanatory. on line 21 you have request $_POST["recaptcha_response_field"]. It does not exists.

Do spell check. Also remember index are case sensitive. Fix it
Mar 12 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.