Jump to content


Photo

Requiered fields


  • Please log in to reply
1 reply to this topic

#1 destined

destined
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationFlorida

Posted 10 April 2006 - 07:47 PM

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

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

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

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

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

and where do i put it
<?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);
?>

EDIT BY OBER: PLEASE USE CODE TAGS WHEN POSTING CODE




thanks ober
[!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--][!--fonto:Comic Sans Ms--][span style="font-family:Comic Sans Ms"][!--/fonto--]May God bless you today and always[!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--]
[a href="http://www.destinedtowin.org/" target="_blank"]you are Destined To Win[/a]

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 10 April 2006 - 07:54 PM

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

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.

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users