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 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.

I think you can add validation after this line :

if ($_POST['form_submitted'] == '1') {
## Form submitted, user registering!

the most simple php script to check required fields is :

if($required01 == "") {
   echo "You must fill required01";
}

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.