Comments and Form Variables

From: Date: Fri, 12 Dec 2003 13:23:20 +0000
Subject: Comments and Form Variables
Groups: php.general 
Request: Send a blank email to php-general+get-172567@lists.php.net to get a copy of this message
Greetings! First time posting. Hope this is the right place. Feel free to email directly or CC. I am trying to get up to speed on using PHP. One of the fastest ways I learn is by reading commented code snippets. I am asking for 2 things. 1. Can someone please 'comment' the below code snippet. And could they do it in great detail? This code enters the Form data into database. 2. I want to add the Mail() to this code block. What I do not know is how to turn the Form objects into Variables... e.g. "GetSQLValueString($HTTP_POST_VARS['FIRST_NAME'], "text")," ...that I can then use in the Mail() itself. I have an idea that the Form objects are somehow automatically Global Variables. Here is code snippet: <?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; } $editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; } if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO comments (FIRST_NAME, LAST_NAME, EMAIL, COMMENTS) VALUES (%s, %s, %s, %s)",
                      GetSQLValueString($HTTP_POST_VARS['FIRST_NAME'], "text"),
                      GetSQLValueString($HTTP_POST_VARS['LAST_NAME'], "text"),
                      GetSQLValueString($HTTP_POST_VARS['EMAIL'], "text"),
                      GetSQLValueString($HTTP_POST_VARS['COMMENTS'], "text"));
mysql_select_db($database_connGlobal, $connGlobal); $Result1 = mysql_query($insertSQL, $connGlobal) or die(mysql_error()); *** I KNOW THAT THE MAIL() WILL GO HERE*** $insertGoTo = "insertOK.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> howard grämer New York City hagdb@hotmail.com _________________________________________________________________ Winterize your home with tips from MSN House & Home. http://special.msn.com/home/warmhome.armx

« previous php.general (#172567) next »