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);
?>
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:
by: ChrisStanyonPosted on 2009-10-26 at 17:24:34ID: 25668328
Hi,
'll need that on any page that uses sessions.
You need to make sure you call session_start() before you start working with sessions. Make it the first line of your script i.e
<?php
session_start();
You