[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

insert record store new id in session

Asked by Witheet in PHP and Databases

Tags: php mysql

Hello,

I am trying to insert a new record in to database and store the id of newly inserted record in a session variable.
I will then use a recordset on the redirect page and us the session variable to find the corresponding record
All seems to work fine on the insert part but the session variable seems to stay empy...
I also have a few conditions that have to be met befor the insert takes place.. I will place code for insert and redirect page below...
These conditions are bascically just check new username functions that I use for slightly different purpose...
Maybe also good to know... New to php... using dreamweaver...

Hope anyone can help me figure out what I am doing wrong...


Tnx in advance

WKR
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
insert.php
<?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;
}
}
 
// *** Redirect if Code is not present in table Codes
	$MM_myflag="MM_insert";
if (isset($_POST[$MM_myflag])) {
  $MM_mydupKeyRedirect="invalid.php";
  $myloginUsername = $_POST['Code'];
  $myLoginRS__query = sprintf("SELECT C_Codes FROM Code WHERE C_Codes<>%s", GetSQLValueString($myloginUsername, "text"));
  mysql_select_db($database_Site, $Site);
  $myLoginRS=mysql_query($myLoginRS__query, $Site) or die(mysql_error());
  $myloginFoundUser = mysql_num_rows($myLoginRS);
 
  //the code was not found - can not add the requested entry
  if($myloginFoundUser){
    $MM_myqsChar = "?";
    //append the code to the redirect page
    if (substr_count($MM_mydupKeyRedirect,"?") >=1) $MM_myqsChar = "&";
    $MM_mydupKeyRedirect = $MM_mydupKeyRedirect . $MM_myqsChar ."code=".$myloginUsername;
    header ("Location: $MM_mydupKeyRedirect");
    exit;
  }
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if(isset($mm_abort_edit) && $mm_abort_edit)
{
}
else
{		
 
// *** Redirect if Code has already been used
	$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="denied.php";
  $loginUsername = $_POST['Code'];
  $LoginRS__query = sprintf("SELECT I_Codes FROM Entries WHERE I_Codes=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_Site, $Site);
  $LoginRS=mysql_query($LoginRS__query, $Site) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
 
  //the code was found - can not add the used code as entry
  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the code to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."code=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if(isset($mm_abort_edit) && $mm_abort_edit)
{
}
else
{		
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Inzendingen (I_Codes, I_Sex, I_Age, I_Store) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['Code'], "text"),
                       GetSQLValueString($_POST[Sex], "text"),
                       GetSQLValueString($_POST[Age], "double"),
                       GetSQLValueString($_POST[Store], "text"));
 
  mysql_select_db($database_Site, $Site);
  $Result1 = mysql_query($insertSQL, $Site) or die(mysql_error());
  $sessionName = "Inzending_Id";
$_SESSION[$sessionName] = mysql_insert_id();
  $insertGoTo = "approved.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
}
?>
 
approved.php
<?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;
}
}
 
$colname_Winnaar = "-1";
if (isset($_SESSION['Inzending_Id'])) {
  $colname_Winnaar = (get_magic_quotes_gpc()) ? $_SESSION['Inzending_Id'] : addslashes($_SESSION['Inzending_Id']);
}
mysql_select_db($database_Site, $Site);
$query_Winnaar = sprintf("SELECT * FROM Entries, WinIds WHERE I_Id = %s AND W_Number = I_Id", GetSQLValueString($colname_Winnaar, "int"));
$Winnaar = mysql_query($query_Winnaar, $Site) or die(mysql_error());
$row_Winnaar = mysql_fetch_assoc($Winnaar);
$totalRows_Winnaar = mysql_num_rows($Winnaar);
?>
[+][-]10/26/09 05:24 PM, ID: 25668328Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Tags: php mysql
Sign Up Now!
Solution Provided By: ChrisStanyon
Participating Experts: 2
Solution Grade: A
 
[+][-]10/26/09 05:26 PM, ID: 25668340Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625