Jump to content

Requiered fields


destined

Recommended Posts

i dont know what i am doing Would soneone give me a Requiered fields script Please

I tryed
[code]
if (isset($_POST["submit"]))
{

// Check for empty fields
if ($_POST["email"] == "")
{
     die("Please fill out all fields");
}
[/code]

I tryed
[code]
if($_POST['required_field_1'] == "" || $_POST['required_field_2'] == "" || ..... || $_POST['required_field_n'] == ""){
//put your error here
}
[/code]

Do i put [!--coloro:#993300--][span style=\"color:#993300\"][!--/coloro--]echo[!--colorc--][/span][!--/colorc--] for the error

and where do i put it
[code]
<?php require_once('Connections/destined_test.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
if ((isset($_POST['emailaddress'])) && ($_POST['emailaddress'] != "")) {
  $deleteSQL = sprintf("DELETE FROM newsletter WHERE emailaddress=%s",
                       GetSQLValueString($_POST['emailaddress'], "text"));

  mysql_select_db($database_destined_test, $destined_test);
  $Result1 = mysql_query($deleteSQL, $destined_test) or die(mysql_error());

  $deleteGoTo = "unsubscribed.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}



mysql_select_db($database_destined_test, $destined_test);
$query_rsUnsubscribe = "SELECT * FROM newsletter";
$rsUnsubscribe = mysql_query($query_rsUnsubscribe, $destined_test) or die(mysql_error());
$row_rsUnsubscribe = mysql_fetch_assoc($rsUnsubscribe);
$totalRows_rsUnsubscribe = mysql_num_rows($rsUnsubscribe);
?>
[/code]

[b]EDIT BY OBER: PLEASE USE CODE TAGS WHEN POSTING CODE[/b]




thanks ober
Link to comment
Share on other sites

[code]
if($_POST['required_field_1'] == "" || $_POST['required_field_2'] == "" || ..... || $_POST['required_field_n'] == ""){
//put your error here
}
[/code]

Should work, but I'd recommend using the trim function around your post variables in case they hit the space bar in the box or something else got screwy.

And it goes at the top of whatever page you do your processing on. Normally you'd submit a form to the same page and if the if statement fails, you display the error message and show the form again. If you're going to go as far as highlighting the ones they missed, you're going to have to set a bunch of flags to change the look of those fields in the form.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.