| | |
i have an issue with required fields i cant understand any of the scripts ive seen.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
im confused. i got captcha in there and it works but i need required fields as well.
i also dont know where to put the script in my code:
PHP Syntax (Toggle Plain Text)
<?php session_start(); ?> <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('The code you entered was incorrect. go back and try again.'); } if ($_POST['form_submitted'] == '1') { ## Form submitted, user registering! } else{ ## No value found, user activating account! } mysql_connect("localhost", datasbase, pass) or die(mysql_error()); mysql_select_db("tablenamething") or die(mysql_error()); if ($_POST['form_submitted'] == '1') { ##User is registering, insert data until we can activate it $activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand(); $username = mysql_real_escape_string($_POST[username]); $password = mysql_real_escape_string($_POST[password]); $email = mysql_real_escape_string($_POST[email]); $sex = mysql_real_escape_string($_POST[sex]); $age = mysql_real_escape_string($_POST[age]); $location = mysql_real_escape_string($_POST[location]); $ethnicity = mysql_real_escape_string($_POST[ethnicity]); $marital = mysql_real_escape_string($_POST[marital]); $sexuality = mysql_real_escape_string($_POST[sexuality]); $haircolor = mysql_real_escape_string($_POST[haircolor]); $name = mysql_real_escape_string($_POST[name]); $eye = mysql_real_escape_string($_POST[eye]); $hairtype = mysql_real_escape_string($_POST[hairtype]); $weight = mysql_real_escape_string($_POST[weight]); $height = mysql_real_escape_string($_POST[height]); $ip = mysql_real_escape_string($_POST[ip]); $date = mysql_real_escape_string($_POST[date]); $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')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration."; ##Send activation Email $to = $_POST[email]; $subject = " socialemo.com Registration"; $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"; $headers = 'From: noreply@ socialemo.com' . "\r\n" . 'Reply-To: noreply@ socialemo.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } else { ##User isn't registering, check verify code and change activation code to null, status to activated on success $queryString = $_SERVER['QUERY_STRING']; $query = "SELECT * FROM users"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if ($queryString == $row["activationkey"]){ echo "Congratulations!" . $row["username"] . " is now a member of socialemo.com."; $sql="UPDATE users SET activationkey = '', status='activated' WHERE (id = $row[id])"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } } } } ?>
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.
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 9
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 :
the most simple php script to check required fields is :
PHP Syntax (Toggle Plain Text)
if ($_POST['form_submitted'] == '1') { ## Form submitted, user registering!
PHP Syntax (Toggle Plain Text)
if($required01 == "") { echo "You must fill required01"; }
Re: i have an issue with required fields i cant understand any of the scripts ive seen.
0
#3 Apr 21st, 2009
![]() |
Other Threads in the PHP Forum
- Previous Thread: mysql_real_esc_str expecting string
- Next Thread: updating data in mysql database using php forms
Views: 302 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google head href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql number oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





