Jump to content

mysql insert loop


wizardry

Recommended Posts

i have have the code working out side of using dw to create the form.

 

here is the code maybe another set of eyes could help.

 

thanks in advance!

 

code:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO user (user_Id, UEA, UEAP) VALUES (null, %s, %s)", 
				   GetSQLValueString($_POST['user_Id'], "int"),
                       GetSQLValueString($_POST['UEA'], "text"),
                       GetSQLValueString($_POST['UEAP'], "text"));
					  
$insertSQL1 = sprintf("insert into uname (uname_Id, user_Id_fk, Fname, Lname) values ( LAST_INSERT_ID(), LAST_INSERT_ID(), %s, %s )",															                       GetSQLValueString($_POST['uname_Id'], "int"),
                       GetSQLValueString($_POST['user_Id_fk'], "int"),
                       GetSQLValueString($_POST['Fname'], "text"),
                       GetSQLValueString($_POST['Lname'], "text"));

$insertSQL2 = sprintf("insert into uzip (uname_Id_fk, uzip_Id, Zip) VALUES (LAST_INSERT_ID(), null, %s,)",											  					   GetSQLValueString($_POST['uname_Id_fk'], "int"),
                       GetSQLValueString($_POST['uzip_Id'], "int"),
                       GetSQLValueString($_POST['Zip'], "text"));

//----------------- db name ------------- db connection
  mysql_select_db($database_user, $Schema);
  $Result1 = mysql_query($insertSQL, $Schema) or die(mysql_error());
  
  mysql_select_db($database_uname, $Schema);
  $Result2 = mysql_query($insertSQL1, $Schema) or die(mysql_error());

  mysql_select_db($database_uzip, $Schema);
  $Result3 = mysql_query($insertSQL2, $Schema) or die(mysql_error());

  $insertGoTo = "userdataset.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Email Address:</td>
      <td><input type="text" name="UEA" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Password:</td>
      <td><input type="password" name="UEAP" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">First Name:</td>
      <td><input type="text" name="Fname" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Last Name:</td>
      <td><input type="text" name="Lname" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Zip:</td>
      <td><input type="text" name="Zip" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"> </td>
      <td><input type="submit" value="Insert record" /></td>
    </tr>
  </table>
  <input type="hidden" name="user_Id" value="" />
  <input type="hidden" name="uname_Id" value="" />
  <input type="hidden" name="user_Id_fk" value="" />
  <input type="hidden" name="uname_Id_fk" value="" />
  <input type="hidden" name="uzip_Id" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>

 

 

Link to comment
Share on other sites

it errors says that table doesn't exists but they do.

 

i created the inital form out side of dw that has the same logic

 

i just created this form in dw using their auto form and applied the logic that i used in the previous one to it.

 

now this errors.

 

i'm new to dw, i like their extras they add to the code for security.

 

dw can connect to each table and schema

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.