Hello PHP experts!
I'm working with
PHP5
MySQL
Mac OSX
I've developed two pages where a user can input his/her info, which goes to a MySQL database. The first page is supposed to pass the newly created 'member_id' (which is an auto-increment field in the 'members' table) to the second page, where I have records going into another table (specialty_groups) that uses 'member_id' as a foreign key.
I've downloaded and used the Dreamweaver Server Behaviour "insert-retrieve ID," which creates a session variable (I've named it 'member_id') equal to 'mysql_insert_id()'.
The problem is, it's not passing this variable to the next page. Am I missing something?
Here's the pertinent code for the first page:
<?php session_start(); ?>
<?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']);
}
// DW Team Insert and Retrieve ID
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo")) {
$insertSQL = sprintf("INSERT INTO member (firstname, lastname, member_no, password, membertype, businessname, street, city, `state`, country, zip, bphone, bfax, mobilephone, email, website, directory_publish, initials, comment, firm_est, firm_size, firm_contact, firm_no_arch, firm_certified, firm_projects, council_district, prof_orgs, currently_serving, curr_serving_detail, interest_serving, interest_serving_detail, media_contact, faculty, sponsor_opps, home_tour, event_locale) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['mbr_fname'], "text"),
GetSQLValueString($_POST['mbr_lname'], "text"),
GetSQLValueString($_POST['memberno'], "int"),
GetSQLValueString($_POST['password1'], "text"),
GetSQLValueString($_POST['mbr_type'], "int"),
GetSQLValueString($_POST['mbr_firmname'], "text"),
GetSQLValueString($_POST['mbr_busaddress'], "text"),
GetSQLValueString($_POST['mbr_city'], "text"),
GetSQLValueString($_POST['mbr_state'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['mbr_zip'], "text"),
GetSQLValueString($_POST['mbr_phone'], "text"),
GetSQLValueString($_POST['mbr_fax'], "text"),
GetSQLValueString($_POST['mbr_mobile'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['mbr_url'], "text"),
GetSQLValueString(isset($_POST['directory_publish']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['initials'], "text"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['firm_est'], "text"),
GetSQLValueString($_POST['firm_size'], "int"),
GetSQLValueString($_POST['firm_contact'], "text"),
GetSQLValueString($_POST['firm_no_arch'], "int"),
GetSQLValueString($_POST['firm_certified'], "text"),
GetSQLValueString($_POST['firm_projects'], "text"),
GetSQLValueString($_POST['council_district'], "text"),
GetSQLValueString($_POST['prof_orgs'], "text"),
GetSQLValueString($_POST['currently_serving'], "text"),
GetSQLValueString($_POST['curr_serving_detail'], "text"),
GetSQLValueString($_POST['interest_serving'], "text"),
GetSQLValueString($_POST['interest_serving_detail'], "text"),
GetSQLValueString($_POST['media_contact'], "text"),
GetSQLValueString($_POST['faculty'], "text"),
GetSQLValueString($_POST['sponsor_opps'], "text"),
GetSQLValueString($_POST['home_tour'], "text"),
GetSQLValueString($_POST['event_locale'], "text"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$_SESSION['member_id'] = mysql_insert_id();
$insertGoTo = "insert_specialty2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_rs_member = "-1";
if (isset($_GET['recordID'])) {
$colname_rs_member = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_connection, $connection);
$query_rs_member = sprintf("SELECT * FROM member WHERE member_id = %s", $colname_rs_member);
$rs_member = mysql_query($query_rs_member, $connection) or die(mysql_error());
$row_rs_member = mysql_fetch_assoc($rs_member);
$totalRows_rs_member = mysql_num_rows($rs_member);
?>
And for the second page:
<?php session_start(); ?>
<?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;
}
session_start();
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
@reset($specialty);
mysql_select_db($database_connection, $connection);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
while (list($key, $val) = @each ($specialty)) {
$insertSQL = sprintf("INSERT INTO specialty_group (specialty, member_id) VALUES (%s,%s)",
GetSQLValueString($val, "text"),
GetSQLValueString($_POST['hiddenMM_id'], "int"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$insertGoTo = "update_complete.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_rsspecialty = "-1";
if (isset($_SESSION['member_id'])) {
$colname_rsspecialty = (get_magic_quotes_gpc()) ? $_SESSION['member_id'] : addslashes($_SESSION['member_id']);
}
mysql_select_db($database_connection, $connection);
$query_rsspecialty = sprintf("SELECT * FROM specialty_group WHERE member_id = %s", $colname_rsspecialty);
$rsspecialty = mysql_query($query_rsspecialty, $connection) or die(mysql_error());
$row_rsspecialty = mysql_fetch_assoc($rsspecialty);
$totalRows_rsspecialty = mysql_num_rows($rsspecialty);
?>
[?CODE]
When I test the pages, the first page uploads info just fine to the database, but it takes FOREVER to download the second page. When it finally downloads, the page is blank.
Please help!!
tHanks -
Charity