destined Posted April 10, 2006 Share Posted April 10, 2006 i dont know what i am doing Would soneone give me a Requiered fields script PleaseI 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 errorand where do i put it[code]<?php require_once('Connections/destined_test.php'); ?><?phpfunction 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 Quote Link to comment Share on other sites More sharing options...
ober Posted April 10, 2006 Share Posted April 10, 2006 [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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.