Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding fields to a table for Dreamweaver-generated code

Posted on 2004-10-16
4
Medium Priority
?
207 Views
Last Modified: 2013-12-12
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_fixmedicare, $conn_fixmedicare);
  $Result1 = mysql_query($insertSQL, $conn_fixmedicare) or die(mysql_error());
===============================================================

Sure would like to learn how to do this.
--John
0
Comment
Question by:Jeiko
  • 2
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12330529
Hi Jeiko,

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['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['pwd'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['catagory'], "text"),
                       GetSQLValueString($_POST['userGroup'], "text"),
                       $_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
0
 

Author Comment

by:Jeiko
ID: 12331114
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_fixmedicare, $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
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 300 total points
ID: 12333190
Have you tried

addslashes("12345.67890.12")

Also, what is GetSQLValueString? Have you tried putting that around your IP? Because if GetSQLValueString checks for get_magic_quotes_gpc(), it may be better...
0
 

Author Comment

by:Jeiko
ID: 12343608
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_medicare.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;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_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_ADDR'], "text"),
                                 date("ymdHis"));

  mysql_select_db($database_conn_medicare, $conn_medicare);
  $Result1 = mysql_query($insertSQL, $conn_medicare) or die(mysql_error());


  $insertGoTo = "site_map_visitor.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question