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 [EMAIL PROTECTED]
_________________________________________________________________
Winterize your home with tips from MSN House & Home. http://special.msn.com/home/warmhome.armx
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php