943,915 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 445
  • PHP RSS
Apr 20th, 2009
0

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

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Apr 21st, 2009
0

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

I think you can add validation after this line :
PHP Syntax (Toggle Plain Text)
  1. if ($_POST['form_submitted'] == '1') {
  2. ## Form submitted, user registering!
the most simple php script to check required fields is :
PHP Syntax (Toggle Plain Text)
  1. if($required01 == "") {
  2. echo "You must fill required01";
  3. }
Reputation Points: 10
Solved Threads: 10
Junior Poster in Training
rudevils is offline Offline
80 posts
since Jan 2008
Apr 21st, 2009
0

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

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!
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009

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: mysql_real_esc_str expecting string
Next Thread in PHP Forum Timeline: updating data in mysql database using php forms





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


Follow us on Twitter


© 2011 DaniWeb® LLC