Jeiko
asked on
Adding fields to a table for Dreamweaver-generated code
I have an input form with data that is loaded into a MySQL database named "fixmedicare." I want to also include the IP address and time and date, which of course does not come from the form. I have tried vaious ways of inserting "$REMOTE_ADDR" and "now()" into the code.
Here is the code that Dreamweaver generated:
========================== ========== ========== ========== ======
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, catagory, userGroup) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST[' firstName' ], "text"),
GetSQLValueString($_POST[' lastName'] , "text"),
GetSQLValueString($_POST[' pwd'], "text"),
GetSQLValueString($_POST[' username'] , "text"),
GetSQLValueString($_POST[' catagory'] , "text"),
GetSQLValueString($_POST[' userGroup' ], "text"));
mysql_select_db($database_ conn_fixme dicare, $conn_fixmedicare);
$Result1 = mysql_query($insertSQL, $conn_fixmedicare) or die(mysql_error());
========================== ========== ========== ========== =======
Sure would like to learn how to do this.
--John
Here is the code that Dreamweaver generated:
==========================
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, catagory, userGroup) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($insertSQL, $conn_fixmedicare) or die(mysql_error());
==========================
Sure would like to learn how to do this.
--John
ASKER
Zyloch,
You've helpd me a lot, but I have one problem. The IP field does not like the multiple decimal points. It's as though when it sees the first decimal point, it treats it as a floating point number and then doesn't know what to do with the next decimal point. Here's the code I'm using that works:
========================== ========== ========== ==========
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, catagory, userGroup, IP, dttm) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST[' firstName' ], "text"),
GetSQLValueString($_POST[' lastName'] , "text"),
GetSQLValueString($_POST[' pwd'], "text"),
GetSQLValueString($_POST[' username'] , "text"),
GetSQLValueString($_POST[' catagory'] , "text"),
GetSQLValueString($_POST[' userGroup' ], "text"),
"123456789012",
date(ymdHis));
mysql_select_db($database_ conn_fixme dicare, $conn_fixmedicare);
$Result1 = mysql_query($insertSQL, $conn_fixmedicare) or die(mysql_error());
========================== ========== ========== ========== =====
If I put more than one decimal point in the string "123456789012", it fails. It seems that the "%s" format would take care of this.
Any suggestions?
--John
You've helpd me a lot, but I have one problem. The IP field does not like the multiple decimal points. It's as though when it sees the first decimal point, it treats it as a floating point number and then doesn't know what to do with the next decimal point. Here's the code I'm using that works:
==========================
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, catagory, userGroup, IP, dttm) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
"123456789012",
date(ymdHis));
mysql_select_db($database_
$Result1 = mysql_query($insertSQL, $conn_fixmedicare) or die(mysql_error());
==========================
If I put more than one decimal point in the string "123456789012", it fails. It seems that the "%s" format would take care of this.
Any suggestions?
--John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Zyloch,
I finally had success with the REMOTE_ADDR. I used the GetSQLValueString function as you suggested. Here is the complete code for your info:
========================== ========== ========== ========== ===
<?php require_once('Connections/ conn_medic are.php'); ?>
<?php
function GetSQLValueString($theValu e, $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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STR ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE RY_STRING' ]);
}
if ((isset($_POST["MM_insert" ])) && ($_POST["MM_insert"] == "reg_form")) {
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, `state`, catagory, userGroup, IP, dttm) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST[' firstName' ], "text"),
GetSQLValueString($_POST[' lastName'] , "text"),
GetSQLValueString($_POST[' pwd'], "text"),
GetSQLValueString($_POST[' username'] , "text"),
GetSQLValueString($_POST[' state'], "text"),
GetSQLValueString($_POST[' catagory'] , "text"),
GetSQLValueString($_POST[' userGroup' ], "text"),
GetSQLValueString($_SERVER ['REMOTE_A DDR'], "text"),
date("ymdHis"));
mysql_select_db($database_ conn_medic are, $conn_medicare);
$Result1 = mysql_query($insertSQL, $conn_medicare) or die(mysql_error());
$insertGoTo = "site_map_visitor.php";
if (isset($_SERVER['QUERY_STR ING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
//header(sprintf("Location : %s", "site_map_visitor.php"));
header("Location: " . "new_visitor_thank_you.php ");
}
?>
========================== ========== ========== ========== ========
Thanks for your help.
-John
I finally had success with the REMOTE_ADDR. I used the GetSQLValueString function as you suggested. Here is the complete code for your info:
==========================
<?php require_once('Connections/
<?php
function GetSQLValueString($theValu
{
$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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STR
$editFormAction .= "?" . htmlentities($_SERVER['QUE
}
if ((isset($_POST["MM_insert"
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, `state`, catagory, userGroup, IP, dttm) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_SERVER
date("ymdHis"));
mysql_select_db($database_
$Result1 = mysql_query($insertSQL, $conn_medicare) or die(mysql_error());
$insertGoTo = "site_map_visitor.php";
if (isset($_SERVER['QUERY_STR
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
//header(sprintf("Location
header("Location: " . "new_visitor_thank_you.php
}
?>
==========================
Thanks for your help.
-John
Assuming you have the fields IP and JOINED, you would have something like this:
$insertSQL = sprintf("INSERT INTO fixmedicare (firstName, lastName, pswd, emailadd, catagory, userGroup, IP, Joined) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
$_SERVER['REMOTE_ADDR'],
date("l dS of F Y h:i:s A"));
I'm not sure if you use addslashes or something like that in GetSQLValueString(). If so, then you might consider using it for $_SERVER['REMOTE_ADDR'] and the date().
Regards,
Zyloch