i have an issue with required fields i cant understand any of the scripts ive seen.

Reply

Join Date: Apr 2009
Posts: 290
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!!'s Avatar
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

i have an issue with required fields i cant understand any of the scripts ive seen.

 
0
  #1
Apr 20th, 2009
everything doesnt make sense. does anyone know of a very SIMPLE good script to make required fields. ive seen a lot but i dont know what they mean. most of them look like they do like nothing or not all the way. i dont want to use javascript because it can be disabled easily. how about php? anyone know i need to make required fields to like 5 of my about 15 inputs in my form on this page http://socialemo.com/register.php
i also dont know where to put the script in my code:
  1. <?php session_start(); ?>
  2.  
  3.  
  4. <?php
  5. include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
  6.  
  7. $securimage = new Securimage();
  8. if ($securimage->check($_POST['captcha_code']) == false) {
  9. // the code was incorrect
  10. // handle the error accordingly with your other error checking
  11.  
  12. // or you can do something really basic like this
  13. die('The code you entered was incorrect. go back and try again.');
  14. }
  15.  
  16. if ($_POST['form_submitted'] == '1') {
  17.  
  18. ## Form submitted, user registering!
  19.  
  20. } else{
  21.  
  22. ## No value found, user activating account!
  23.  
  24. }
  25.  
  26. mysql_connect("localhost", datasbase, pass) or die(mysql_error());
  27.  
  28. mysql_select_db("tablenamething") or die(mysql_error());
  29.  
  30. if ($_POST['form_submitted'] == '1') {
  31. ##User is registering, insert data until we can activate it
  32. $activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
  33. $username = mysql_real_escape_string($_POST[username]);
  34. $password = mysql_real_escape_string($_POST[password]);
  35. $email = mysql_real_escape_string($_POST[email]);
  36. $sex = mysql_real_escape_string($_POST[sex]);
  37. $age = mysql_real_escape_string($_POST[age]);
  38. $location = mysql_real_escape_string($_POST[location]);
  39. $ethnicity = mysql_real_escape_string($_POST[ethnicity]);
  40. $marital = mysql_real_escape_string($_POST[marital]);
  41. $sexuality = mysql_real_escape_string($_POST[sexuality]);
  42. $haircolor = mysql_real_escape_string($_POST[haircolor]);
  43. $name = mysql_real_escape_string($_POST[name]);
  44. $eye = mysql_real_escape_string($_POST[eye]);
  45. $hairtype = mysql_real_escape_string($_POST[hairtype]);
  46. $weight = mysql_real_escape_string($_POST[weight]);
  47. $height = mysql_real_escape_string($_POST[height]);
  48. $ip = mysql_real_escape_string($_POST[ip]);
  49. $date = mysql_real_escape_string($_POST[date]);
  50.  
  51. $sql="INSERT INTO users (username, password, email, sex, age, location, ethnicity, marital, sexuality, haircolor, name, eye, hairtype, weight, height, ip, date, activationkey, status) VALUES ('$username', '$password', '$email', '$sex', '$age', '$location', '$ethnicity', '$marital', '$sexuality', '$haircolor', '$name', '$eye', '$hairtype', '$weight', '$height', '$ip', '$date', '$activationKey', 'verify')";
  52.  
  53. if (!mysql_query($sql))
  54.  
  55. {
  56.  
  57. die('Error: ' . mysql_error());
  58.  
  59. }
  60.  
  61. echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration.";
  62.  
  63. ##Send activation Email
  64.  
  65. $to = $_POST[email];
  66.  
  67. $subject = " socialemo.com Registration";
  68.  
  69. $message = "Welcome to our website!\r\rYou, or someone using your email address, has almost completed registration at socialemo.com. You can complete registration by clicking the following link:\rhttp://www.socialemo.com/verify.php?$activationKey\r\rIf this is an error, ignore this email and your email will be removed from our database.\r\rRegards, socialemo.com";
  70.  
  71. $headers = 'From: noreply@ socialemo.com' . "\r\n" .
  72.  
  73. 'Reply-To: noreply@ socialemo.com' . "\r\n" .
  74.  
  75. 'X-Mailer: PHP/' . phpversion();
  76.  
  77. mail($to, $subject, $message, $headers);
  78.  
  79.  
  80.  
  81.  
  82. }
  83. else {
  84. ##User isn't registering, check verify code and change activation code to null, status to activated on success
  85.  
  86. $queryString = $_SERVER['QUERY_STRING'];
  87.  
  88. $query = "SELECT * FROM users";
  89.  
  90. $result = mysql_query($query) or die(mysql_error());
  91.  
  92. while($row = mysql_fetch_array($result)){
  93.  
  94. if ($queryString == $row["activationkey"]){
  95.  
  96. echo "Congratulations!" . $row["username"] . " is now a member of socialemo.com.";
  97.  
  98. $sql="UPDATE users SET activationkey = '', status='activated' WHERE (id = $row[id])";
  99.  
  100. if (!mysql_query($sql))
  101.  
  102. {
  103.  
  104. die('Error: ' . mysql_error());
  105.  
  106. }
  107.  
  108. }
  109.  
  110. }
  111.  
  112.  
  113. }
  114.  
  115. ?>

im confused. i got captcha in there and it works but i need required fields as well.
Last edited by SKANK!!!!!; Apr 20th, 2009 at 11:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 79
Reputation: rudevils is an unknown quantity at this point 
Solved Threads: 9
rudevils rudevils is offline Offline
Junior Poster in Training

Re: i have an issue with required fields i cant understand any of the scripts ive seen.

 
0
  #2
Apr 21st, 2009
I think you can add validation after this line :
  1. if ($_POST['form_submitted'] == '1') {
  2. ## Form submitted, user registering!
the most simple php script to check required fields is :
  1. if($required01 == "") {
  2. echo "You must fill required01";
  3. }
If love is blind, why there's a bikini ??

Post your article at Bali Side Notes share your knowledge
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 290
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!!'s Avatar
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

Re: i have an issue with required fields i cant understand any of the scripts ive seen.

 
0
  #3
Apr 21st, 2009
ok thanks. it didnt work there because i had to put it under the variable=[post] looking thing.
and i changed the script to die instead i guess that stops everything die("fill in blah blah"); its working thanks for helping!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 303 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC