Hi -
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 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 'MM_id') equal to 'mysql_insert_id()'.
The problem is, it's not passing this variable to the next page. Am I missing something? Do I need to include a 'session_start()' somewhere?
Here's the pertinent code for the first page: -
<?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($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["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["MM_id"] = mysql_insert_id();
-
$insertGoTo = "insert_specialty2.php";
-
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
-
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
-
$insertGoTo .= $HTTP_SERVER_VARS['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);
-
?>
-
Any help is GREATLY appreciated...
Charity
4 2286
You must have to use session_start() whenever you need to manipulate session variables. Put this on the top of the before, make sure there should not be any sort of output.
You must have to use session_start() whenever you need to manipulate session variables. Put this on the top of the before, make sure there should not be any sort of output.
Thank you! Could you please tell me exactly where in my code the 'session_start()' would go? I've put it in there before - first, at the top of the code, and I tried another time to put it right before the session variable, and it still didn't work - the page just took a really long time to load.
Thanks again.
Charity
Atli 5,058
Expert 4TB
Hi.
The session_start() function should be put at the top of the page, or at least before any output.
Also, I see you use $HTTP_POST_VARS and $HTTP_SERVER_VARS in some places. Although they are still available in PHP5 they are deprecated and you should avoid using them. Use the $_POST and $_SERVER superglobals instead, as you do most of the time.
Thank you for your reply. I've changed the old code to the new - thanks for noticing!
I've been fiddling with it all night, to no avail. I've added the session_start() to the top, I've added session_name(), session_register() - with variables - and nothing.
What happens is when I submit the first page to go to the second (and hopefully pass the session variable) one of two things happens.
Either
1 - the page takes a VERY long time to load, and when it does, it's blank; or,
2 - the second page loads, but when I submit it, it says that the 'member_id' field is null. Also, just for testing, I've added dynamic text to the page that's supposed to contain the Session Variable - it's blank space.
The code for the first page is the same, except that I now have this at the top: -
<?php require_once('../Connections/connection.php'); ?>
-
<?php session_start();
-
-
// *** Redirect if username exists
-
$MM_flag="MM_insert";
-
if (isset($_POST[$MM_flag])) {
-
$MM_dupKeyRedirect="username_in_use.htm";
-
$loginUsername = $_POST['memberno'];
-
$LoginRS__query = "SELECT member_no FROM member WHERE member_no='" . $loginUsername . "'";
-
mysql_select_db($database_connection, $connection);
-
$LoginRS=mysql_query($LoginRS__query, $connection) or die(mysql_error());
-
$loginFoundUser = mysql_num_rows($LoginRS);
-
-
//if there is a row in the database, the username was found - can not add the requested username
-
if($loginFoundUser){
-
$MM_qsChar = "?";
-
//append the username to the redirect page
-
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
-
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
-
header ("Location: $MM_dupKeyRedirect");
-
exit;
-
}
-
}
-
?>
-
<?php
-
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
-
etc.
The second page's code looks like this: -
<?php require_once('../Connections/connection.php'); ?>
-
<?php session_start(); ?>
-
<?php require_once('../Connections/connection.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']);
-
-
}
-
-
@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['hiddenID'], "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['MM_id'])) {
-
$colname_rsspecialty = (get_magic_quotes_gpc()) ? $_SESSION['MM_id'] : addslashes($_SESSION['MM_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);
-
?>
-
Is this more of a help?
Thanks again - the help is so appreciated!
Charity
Sign in to post your reply or Sign up for a free account.
Similar topics
by: WC Justice |
last post by:
I'm assuming this can be done, but I can't seem to get it to work... I'd
like to easily return a single value from a sql statement, something like:
"intNewItems = conn.execute "SELECT COUNT...
|
by: Devesh Aggarwal |
last post by:
Hi,
I have a backup and restore module in my project. The backup uses a typed
dataset object (XSD) to get the data from database and creates a xml file as
the backup file (using the WriteXml...
|
by: Randell D. |
last post by:
Folks,
I have a table of addresses and a seperate table with contact names -
All addresses tie to one or more names - I would like to keep track of
the number of names 'belonging' to an address...
|
by: Hardy Wang |
last post by:
Hi all,
I have the following codes, but SCOPE_IDENTITY() just returns NULL to
me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works
fine!! Since I have a trigger on the...
|
by: Rico |
last post by:
Hello,
I am in the midst of converting an Access back end to SQL Server Express.
The front end program (converted to Access 2003) uses DAO throughout. In
Access, when I use recordset.AddNew I...
|
by: Phil Latio |
last post by:
I have 2 virtually identical tables and wish to move data between them.
Basically one table is called "live_table" and the other is named
"suspended_table" and the only difference is that the...
|
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a...
|
by: Simon Gare |
last post by:
Hi all,
I am trying to retrieve a count of booking entries made 30 days ago, below
is the end of the query I am having problems with.
dbo.booking_form.TimeOfBooking = DATEADD(day, -30,...
|
by: gunnar.sigurjonsson |
last post by:
I´m having some problem retrieving identity value from my newly
inserted row into a view.
I have two tables T1 and T2 which I define as following
CREATE TABLE T1
(
id BIGINT GENERATED ALWAYS...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |