only1wizard
asked on
function variables
hello -
i have a form that displays the data for the user to edit. and it grabs the data to update the database columns.
this is an array so they are able to at most update 10 records at once.
however i have a problem with the form. the html markup is in a function that displays the table to do the updating. and when i do a var_dump of $_POST i get all the variables but when i echo the sql query to see what was captured it comes back as null.
what do i do?
i have a form that displays the data for the user to edit. and it grabs the data to update the database columns.
this is an array so they are able to at most update 10 records at once.
however i have a problem with the form. the html markup is in a function that displays the table to do the updating. and when i do a var_dump of $_POST i get all the variables but when i echo the sql query to see what was captured it comes back as null.
what do i do?
It is probably an issue of variable scope. Functions have their own scope, and they do not share scope with other functions, nor with the main program. This is the page that you need to understand:
http://php.net/manual/en/language.variables.scope.php
As you can see from reading that page, the superglobal arrays like $_POST are available in all scopes, however the variables you define are not. The design strategy behind this is rooted in "encapsulation" which is a way of saying that we do not want our variable names to collide in ways that accidentally overwrite our data.
You also need to get used to programming with error_reporting(E_ALL) set. It will alert you to things like variables out of scope.
http://php.net/manual/en/language.variables.scope.php
As you can see from reading that page, the superglobal arrays like $_POST are available in all scopes, however the variables you define are not. The design strategy behind this is rooted in "encapsulation" which is a way of saying that we do not want our variable names to collide in ways that accidentally overwrite our data.
You also need to get used to programming with error_reporting(E_ALL) set. It will alert you to things like variables out of scope.
ASKER
@omniunlimited
yes it errors and the variables and some of the variables are null is what i ment to say.
QUERY FAIL:
UPDATE footable1 SET fooName='', `Date`=',', fooIdPk='1', initial_time=now() WHERE Id='89' and fooIdPk='1'
yes it errors and the variables and some of the variables are null is what i ment to say.
QUERY FAIL:
UPDATE footable1 SET fooName='', `Date`=',', fooIdPk='1', initial_time=now() WHERE Id='89' and fooIdPk='1'
Thank you. Can I see the code that sets up your SQL?
ASKER
here is the requested data
-- data tables
-- data inserts script for creating records
-- dummy data
-- query
-- here is the
-- data tables
CREATE TABLE `footable` (
`Id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'picture data id',
`FooId` bigint(20) unsigned NOT NULL COMMENT 'picture title id',
`foo` char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'N' COMMENT 'default for schema album',
`fooSize` varchar(45) COLLATE utf8_unicode_ci NOT NULL COMMENT 'picture thumb size',
`fooDefault` char(1) COLLATE utf8_unicode_ci not null default 'N' comment ' default profile picture',
PRIMARY KEY (`Id`,`FooId`),
KEY `fk_fooId` (`fooId`),
CONSTRAINT `fk_fooId` FOREIGN KEY (`fooId`) REFERENCES `footable1` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='picture data schema table'
CREATE TABLE `footable1` (
`Id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'picture title id',
`fooIdPk` bigint(20) unsigned NOT NULL COMMENT 'picture album id',
`fooName` longblob COMMENT 'picture title',
`date0` date NOT NULL COMMENT 'date of picture',
`initial_time` datetime NOT NULL COMMENT 'date created ',
PRIMARY KEY (`Id`,`fooIdPk`))
ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='picture title schema'
-- data inserts script for creating records
#!/bin/bash
# **************************
# dummy records script
# author: theo werntz ii
# date: 09/02/2011
# **************************
a=1
while [ $a -le 10 ]
do
echo "use test; " >> foo_tables.sql;
echo "insert into test.footable1(" >> foo_tables.sql;
echo "Id," >> foo_tables.sql;
echo "fooIdPk," >> foo_tables.sql;
echo "fooName," >> foo_tables.sql;
echo "date0," >> foo_tables.sql;
echo "initial_time)" >> foo_tables.sql;
echo "values" >> foo_tables.sql;
echo "('$a'," >> foo_tables.sql;
echo "'1'," >> foo_tables.sql;
echo "'FooDemo $a'," >> foo_tables.sql;
echo "now()", >> foo_tables.sql;
echo "now());" >> foo_tables.sql;
echo "insert into test.footable(" >> foo_tables.sql;
echo "Id," >> foo_tables.sql;
echo "FooId," >> foo_tables.sql;
echo "foo," >> foo_tables.sql;
echo "fooSize," >> foo_tables.sql;
echo "fooDefault" >> foo_tables.sql;
echo ")" >> foo_tables.sql;
echo "values" >> foo_tables.sql;
echo "(null," >> foo_tables.sql;
echo "'$a'," >> foo_tables.sql;
echo "'N'," >> foo_tables.sql;
echo "'1$a'," >> foo_tables.sql;
echo "'N'" >> foo_tables.sql;
echo ");" >> foo_tables.sql;
let a=a+1
done;
-- dummy data
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('1',
'1',
'FooDemo 1',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'1',
'N',
'11',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('2',
'1',
'FooDemo 2',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'2',
'N',
'12',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('3',
'1',
'FooDemo 3',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'3',
'N',
'13',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('4',
'1',
'FooDemo 4',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'4',
'N',
'14',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('5',
'1',
'FooDemo 5',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'5',
'N',
'15',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('6',
'1',
'FooDemo 6',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'6',
'N',
'16',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('7',
'1',
'FooDemo 7',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'7',
'N',
'17',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('8',
'1',
'FooDemo 8',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'8',
'N',
'18',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('9',
'1',
'FooDemo 9',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'9',
'N',
'19',
'N'
);
use test;
insert into test.footable1(
Id,
fooIdPk,
fooName,
date0,
initial_time)
values
('10',
'1',
'FooDemo 10',
now(),
now());
insert into test.footable(
Id,
FooId,
foo,
fooSize,
fooDefault
)
values
(null,
'10',
'N',
'110',
'N'
);
-- query
select
a.Id,
a.FooId,
a.foo,
a.fooSize,
a.fooDefault,
b.Id,
b.fooIdPk,
b.fooName,
b.date0,
b.initial_time
from
footable as a,
footable1 as b
where b.fooIdPk='1'
-- here is the
<?php
foreach( $fooArray as $fooId )
{
// title table
$updateSQL1 = sprintf("UPDATE footable1 SET name=%s, `Date`=%s, fooIdPk='$fooId', initial_time=now() WHERE Id=%s", GetSQLValueString($_POST['name'][$NetId], "text"),
GetSQLValueString($_POST['Date0'][$NetId], "date"),
GetSQLValueString($_POST['fooId'][$NetId], "int"));
mysql_select_db($database_foo, $Foo);
$Result1 = mysql_query($updateSQL1, $Foo);// or die(mysql_error());
// data table
$update0 = sprintf("UPDATE `footable` SET `Foo`=%s, `FooDefault`=%s, `FooSize`=%s WHERE `FooId`=%s"
,GetSQLValueString($fooId)
,GetSQLValueString(isset($_POST['Foo'][$fooId]) ? "true" : "", "defined","'Y'","'N'")
,GetSQLValueString(isset($_POST['FooDefault'][$fooId]) ? "true" : "", "defined","'Y'","'N'")
,GetSQLValueString($_POST['FooSize'][$fooId], "int")
);
mysql_select_db($database_foo, $Foo);
$Result = mysql_query($update0, $Foo)or die(mysql_error());
}
?>
OK, thanks. Now can you post the code for your form?
ASKER
heres the form info
let me know if this helps i havent posted the function that displays the form.
thanks in advance for your help
echo '<form id="formFoo" name="formFoo" method="POST" action="' ."$editFormAction". '">';
echo '<table border="1" align="left" width="100%" cellpadding="0" cellspacing="0">' ;
echo 'fooName:' . '<input type="text" name="fooName[]" id="fooName" value="' ."$fooName". '"/>' . '<br />';
echo "<tr>";
echo "<td>";
echo "<br />";
echo 'Date: ' . '<input type="text" name="Date0[]" id="Date0" value="' ."$Dates". '"/>' . '<br />';
echo '<br />';
echo 'foo: ';
if($foo == 'Y')
{
echo '<input type="checkbox" name="foo[]" id="foo" value="" checked="checked" />';
}
else
{
echo '<input type="checkbox" name="foo[]" id="foo" value="" />';
}
echo 'foo default:';
if($fooDefault == 'Y')
{
echo '<input type="checkbox" name="fooDefault[]" id="fooDefault" value="" checked="checked" />';
}
else
{
echo '<input type="checkbox" name="fooDefault[]" id="fooDefault" value="" />';
}
echo "<br />";
$fooSize = filesize($img_thumb); grab image thumb path
echo '<input type="hidden" id="foosize" name="foosize[]" value="' ."$fooSize" . '"/>';
echo '<input type="hidden" id="FooId" name="FooId[]" value="' ."$FooId". '" />';
echo "<br />";
echo "</td>";
echo "</tr>";
echo '<tr><td><input type="submit" name="Submit" value="Submit" /></td></tr>';
echo '</table>' ; // ending the table
echo '<input type="hidden" name="MM_update" value="formFoo" />' ;
echo '</form>'; // end of form
let me know if this helps i havent posted the function that displays the form.
thanks in advance for your help
OK, a couple things. First off, in the following code
you are accessing $_POST['name']. There is no name name in your form (and it is not good practice to name one of your fields "name" anyway). You might check your function GetSQLValueString() for how it is handling your date.
Second, you stated that everything was going into an array so that they could update up to 10 records at a time. How?
The form code you gave is confusing. You are using arrays without indexes, and I can see only one field of each type. Generally, when you use an array for a name, you would set up multiple fields with the same array and different indexes. For example:
I'd appreciate it if you could give a little explanation as to how this code is supposed to do what you say its supposed to do.
$updateSQL1 = sprintf("UPDATE footable1 SET name=%s, `Date`=%s, fooIdPk='$fooId', initial_time=now() WHERE Id=%s", GetSQLValueString($_POST['name'][$NetId], "text"),
GetSQLValueString($_POST['Date0'][$NetId], "date"),
GetSQLValueString($_POST['fooId'][$NetId], "int"));
you are accessing $_POST['name']. There is no name name in your form (and it is not good practice to name one of your fields "name" anyway). You might check your function GetSQLValueString() for how it is handling your date.
Second, you stated that everything was going into an array so that they could update up to 10 records at a time. How?
The form code you gave is confusing. You are using arrays without indexes, and I can see only one field of each type. Generally, when you use an array for a name, you would set up multiple fields with the same array and different indexes. For example:
echo '<input type="checkbox" name="foo[first]" id="foo1" value="" />';
echo '<input type="checkbox" name="foo[second]" id="foo2" value="" />';
echo '<input type="checkbox" name="foo[third]" id="foo3" value="" />';
I'd appreciate it if you could give a little explanation as to how this code is supposed to do what you say its supposed to do.
ASKER
i would like to have help and put foo their to cover actual form elements i will post the complete form with out foo elements. sorry for any confusion.
ASKER
here is the complete page.
<?php require_once('../Connections/Pictures.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;
}
}
if (isset($_GET['AlbumName'])) {
$AlbumName_Id = htmlspecialchars($_GET['AlbumName']);
}
// added to use string variables in querys from seperate functions.
//$Net = array();
$Net = explode(',' , $_SESSION['Image_String_Id']);
$Row_Count = $_SESSION['num'];
// table variables
$Title_Name = $_SESSION['Title_Name'];
$Date0 = $_SESSION['Date0'];
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1"))
{
// debugging the form post values
//for ($w=0;$w<count($num);$w++) {
//echo '<br />', 'Title:', $_POST['Title'.$w], '<br />', 'Date:', $_POST['Date0'.$w], '<br />', 'TitleId:', $_POST['TitleId'.$w], '<br />', 'Default:', $_POST['Default'.$w], '<br />', 'DefaultPP:', $_POST['DefaultProfilePic'.$w], '<br />', 'PicThumbSize:', $_POST['PicThumbSize'.$w], '<br />', 'TitleId:', $_POST['TitleId'.$w];
//} // end of for loop
foreach($Net as $NetId) {
// echo "$NetId<br />";
for ($w=0;$w<count($Row_Count);$w++) {
$updateSQL = sprintf("UPDATE AITitle SET Title=aes_encrypt('$Title_Name', '$PUkey'), `Date`='$Date0', AlbumId='$AlbumName_Id', DateCreated=now() WHERE Id=$NetId", GetSQLValueString($_POST['Title'.$w][$NetId], "text"),
GetSQLValueString($_POST['Date0'.$w][$NetId], "date"));
//GetSQLValueString($_POST['TitleId'.$w][$NetId], "int"));
mysql_select_db($database_Pictures, $Pictures);
$Result1 = mysql_query($updateSQL, $Pictures);// or die(mysql_error());
$updateSQL2 = sprintf("UPDATE AIData SET `Default`=%s, DefaultProfilePic=%s, PicThumbSize=%s WHERE TitleId=$NetId",
GetSQLValueString(isset($_POST['Default'.$w][$NetId]) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['DefaultProfilePic'.$w][$NetId]) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['PicThumbSize'.$w][$NetId], "int"));
//GetSQLValueString($_POST['TitleId'.$w][$NetId], "int"));
mysql_select_db($database_Pictures, $Pictures);
$Result2 = mysql_query($updateSQL2, $Pictures); // or die(mysql_error());
echo '<br />', 'Title:', $_POST['Title'.$w], 'Date: ', $_POST['Date'.$w], 'Fk: ', $_POST['TitleId'.$w];
// IF mysql_query() RETURNS FALSE, SHOW THE ERROR
if (!$Result1)
{
$errmsg = mysql_errno() . ' ' . mysql_error();
echo "<br/>QUERY FAIL: ";
echo "<br/>" . "$updateSQL" . "<br/>";
die($errmsg);
}
else
{
echo "<br/>QUERY Succeed: ";
echo "<br/>" . "$updateSQL" . "<br/>";
}
if (!$Result2)
{
$errmsg = mysql_errno() . ' ' . mysql_error();
echo "<br/>QUERY FAIL: ";
echo "<br/>" . "$updateSQL2" . "<br/>";
die($errmsg);
}
else
{
echo "<br/>QUERY Succeed: ";
echo "<br/>" . "$updateSQL2" . "<br/><br/><br /><br/><br/><br /><br/><br/><br /><br/><br/><br /><br/><br/><br /><br/><br/><br /><br/><br/><br />";
}
var_dump($_POST);
} // end for statement
}// end foreach
/*$insertGoTo = "./manage_pictures.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
*/
//} // END OF while loop
} // end of if for the form
mysql_select_db($database_Pictures, $Pictures);
$query_AlbumsList = "SELECT a.Id as Id, a.AlbumName as Album, a.AlbumDate as Date FROM ASAlbums a, ASManyAlbums b WHERE b.AlbumId=a.Id and b.UserId='$UserId' and a.Id='$AlbumName_Id'";
$AlbumsList = mysql_query($query_AlbumsList, $Pictures) or die(mysql_error());
$row_AlbumsList = mysql_fetch_assoc($AlbumsList);
$totalRows_AlbumsList = mysql_num_rows($AlbumsList);
mysql_select_db($database_Pictures, $Pictures);
$query_albumCheck = "select Title from ASTitle where albumid='$AlbumName_Id'";
$albumCheck = mysql_query($query_albumCheck, $Pictures) or die(mysql_error());
$row_albumCheck = mysql_fetch_assoc($albumCheck);
$totalRows_albumCheck = mysql_num_rows($albumCheck);
$totalRows_albumCheck1 = mysql_num_rows($albumCheck);
require_once('../Connections/visitors_tracking.php');
?>
<!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><?php echo $UserName; ?> Photo Loader Display</title>
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
background-color: #0E03D6;
}
.thrColLiqHdr #container {
width: 80%; /* this will create a container 80% of the browser width */
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
}
.thrColLiqHdr #header {
background: #FFFFFF;
padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
}
.thrColLiqHdr #header h1 {
margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}
/* Tips for sidebars:
1. Since we are working in percentages, it's best not to use side padding on the sidebars. It will be added to the width for standards compliant browsers creating an unknown actual width.
2. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".thrColLiqHdr #sidebar1 p" rule.
3. Since Explorer calculates widths after the parent element is rendered, you may occasionally run into unexplained bugs with percentage-based columns. If you need more predictable results, you may choose to change to pixel sized columns.
*/
.thrColLiqHdr #sidebar1 {
float: left; /* this element must precede in the source order any element you would like it be positioned next to */
width: 0%; /* since this element is floated, a width must be given */
background: #FFFFFF; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 0px 0; /* top and bottom padding create visual space within this div */
}
.thrColLiqHdr #sidebar2 {
float: right; /* this element must precede in the source order any element you would like it be positioned next to */
width: 0%; /* since this element is floated, a width must be given */
background: #FFFFFF; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 0px 0; /* top and bottom padding create visual space within this div */
}
.thrColLiqHdr #sidebar1 p, .thrColLiqHdr #sidebar1 h3, .thrColLiqHdr #sidebar2 p, .thrColLiqHdr #sidebar2 h3 {
margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
margin-right: 10px;
}
/* Tips for mainContent:
1. the space between the mainContent and sidebars is created with the left and right margins on the mainContent div.
2. to avoid float drop at a supported minimum 800 x 600 resolution, elements within the mainContent div should be 300px or smaller (this includes images).
3. in the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs.
*/
.thrColLiqHdr #mainContent {
margin: 0 24% 0 23.5%; /* the right and left margins on this div element creates the two outer columns on the sides of the page. No matter how much content the sidebar divs contain, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the sidebar spaces when the content in each sidebar ends. */
}
.thrColLiqHdr #footer {
padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
background:#FFFFFF;
}
.thrColLiqHdr #footer p {
margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}
/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain its child floats */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
#apDiv1 {
position:absolute;
left:119px;
top:358px;
width:151px;
height:34px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:279px;
top:357px;
width:748px;
height:36px;
z-index:2;
}
-->
</style><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.thrColLiqHdr #sidebar2, .thrColLiqHdr #sidebar1 { padding-top: 30px; }
.thrColLiqHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#apDiv3 {
position:absolute;
left:281px;
top:9px;
width:731px;
height:90px;
z-index:3;
}
-->
</style>
</head>
<body class="thrColLiqHdr">
<div id="apDiv1"><img src="../_wizardimages/only1wizard_logo.gif" width="153" height="34" alt="only1wizard_logo" longdesc="http://www.only1wizard.com" /></div>
<div id="apDiv2">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a href="../home/home.php">Home</a></li>
<li><a href="../browse/browse.php">Browse</a></li>
<li><a href="../source/source.php" class="MenuBarItemSubmenu">Source</a>
<ul>
<li><a href="../home/manage_profile.php" title="Edit Profile">Manage Source</a></li>
<li><a href="../blogs/manage_blogs.php">Manage Blogs</a></li>
<li><a href="../comments/comments.php">Comments</a></li>
<li><a href="../pictures/albums.php" class="MenuBarItemSubmenu">Pictures</a>
<ul>
<li><a href="../pictures/manage_pictures_albums.php" title="Manage Pictures">Manage Pictures</a></li>
<li><a href="../pictures/manage_albums.php" title="Manage Albums">Manage Albums</a></li>
<li><a href="../pictures/add_photo.php" title="Add Pictures">Upload Pictures</a></li>
</ul>
</li>
<li><a href="../mail/messages.php">Messages</a></li>
<li><a href="../schooling/schooling.php" title="Schooling">Schooling</a></li>
</ul>
</li>
<li><a href="../extras.php">Extras</a> </li>
<li><a href="../aboutus.php">About Us</a></li>
</ul>
<?php
if (isset($friendId)) {
echo ' <a href="../logout.php">Log Out </a>';
}
?>
</div>
<div id="apDiv3"></div>
<div id="container">
<div id="header">
<h1> </h1>
<p> </p>
<p> </p>
<!-- end #header --></div>
<div id="sidebar1">
<h3> </h3>
<!-- end #sidebar1 --></div>
<div id="sidebar2">
<h3> </h3>
<!-- end #sidebar2 --></div>
<div id="mainContent">
<h1> </h1>
<h2> </h2>
<?php
/*
original author: http://www.dmxzone.com/go?16444
modified by: theo werntz ii
date: 01312010
purpose: use as a tempary script for upload and resizing images, until i learn more about creating and resizing images in php
modified notes: changed directory paths for server uploads,
changing the file storage name,
changing the file storage area,
moving the uploaded images and resized to users container
*/
/*
echo "<pre>";
var_dump($_FILES);
echo "</pre>";
*/
set_time_limit(0);
$link = $Pictures;//put in your db connection details here
// create the array of images
$cons_image=$_FILES['cons_image'] ;
// CREATE AN ARRAY
$arr = array();
// for processing the while loop for new directory
$z = array();
$image_title_id = array();
//define a maxim size for the uploaded images
define ("MAX_SIZE","9216");
// define the width and height for the thumbnail
// note that theese dimmensions are considered the maximum dimmension and are not fixed,
// because we have to keep the image ratio intact or it will be deformed
define ("WIDTH","200"); //set here the width you want your thumbnail to be
define ("HEIGHT","200"); //set here the height you want your thumbnail to be.
define ("WIDTH2","700"); //set here the width you want your thumbnail to be
define ("HEIGHT2","700"); //set here the height you want your thumbnail to be.
// this is the function that will create the thumbnail image from the uploaded image
// the resize will be done considering the width and
// height defined, but without deforming the image
function make_thumb($img_name,$filename,$new_w,$new_h){
//get image extension.
$ext=getExtension($img_name);
//creates the new image using the appropriate function from gd library
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
if(!strcmp("gif",$ext))
$src_img=imagecreatefromgif($img_name);
//gets the dimmensions of the image
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
// next we will calculate the new dimmensions for the thumbnail image
// the next steps will be taken:
// 1. calculate the ratio by dividing the old dimmensions with the new ones
// 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
// and the height will be calculated so the image ratio will not change
// 3. otherwise we will use the height ratio for the image
// as a result, only one of the dimmensions will be from the fixed ones
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}else{
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
// we create a new image with the new dimmensions
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
// resize the big image to the new created one
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
// output the created image to the file. Now we will have the thumbnail into the file named by $filename
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
if (!strcmp("gif",$ext))
imagegif($dst_img,$filename);
//destroys source and destination images.
imagedestroy($dst_img);
imagedestroy($src_img);
}
// This function reads the extension of the file.
// It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
// This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an error occures. If the error occures the file will not be uploaded.
$errors=0;
// checks if the form has been submitted
if(isset($_POST['Submit'])){
for ($i=0;$i<count($cons_image);$i++) {
//reads the name of the file the user submitted for uploading
$image=$_FILES['cons_image']['name'][$i];
// if it is not empty
if (!empty($image))
{
// get the original name of the file from the clients machine
$filename = stripslashes($_FILES['cons_image']['name'][$i]);
// get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
// if it is not a known extension, we will suppose it is an error, print an error message
//and will not upload the file, otherwise we continue
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
echo 'Unknown extension! Please use .gif, .jpg or .png files only.';
$errors=1;
}else{
// get the size of the image in bytes
// $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which
//the uploaded file was stored on the server
$size=getimagesize($_FILES['cons_image']['tmp_name'][$i]);
$sizekb=filesize($_FILES['cons_image']['tmp_name'][$i]);
//compare the size with the maxim size we defined and print error if bigger
if ($sizekb > MAX_SIZE*1024)
{
echo 'You have exceeded the 9MB size limit!';
$errors=1;
}
// change from a 1000 to possible include each user to have 1 million pictures to their account
$rand= mt_rand(0, 1000000);
//we will give an unique name, for example a random number
$image_name=$rand.'.'.$extension;
/*
get the directory value from the users choice of directory to select to upload to before uploading
*/
// mysql_select_db($database_AlbumsList, $AlbumsList);
$album_name_id = $AlbumName_Id;
$album_name = $row_AlbumsList['Album'] ;
$album_users_path = "$UserName";
// $album_web_root = "/";
$album_users_container = "../mArea/";
$album_users_directory = "/pictures/";
$album = "$album_users_container$album_users_path$album_users_directory$album_name/";
$album_thumbs = "$album_users_container$album_users_path$album_users_directory$album_name/thumbs/";
$album_choice = "$album";
//the new name will be containing the full path where will be stored (images folder)
$consname="$album".$image_name; //change the image/ section to where you would like the original image to be stored
$consname2="$album_thumbs".$image_name;
//change the image/thumb to where you would like to store the new created thumb nail of the image
$copied = copy($_FILES['cons_image']['tmp_name'][$i], $consname);
$copied = copy($_FILES['cons_image']['tmp_name'][$i], $consname2);
// $PicThumbSize = filesize($consname2[$i]);
// $_SESSION['PicThumbSize'] = $PicThumbSize;
// check if record set is null
if (($totalRows_albumCheck == 0) && ($i < 1 )) {
//if($i < 1 ) {
//$w = $i ;
// insert into the title table the chosen album
$sql0 = sprintf("insert into AITitle (Id, Title, `Date`, AlbumId, DateCreated) values ( null, aes_encrypt(' ', '$PUkey'), now(), '$album_name_id', now())");
// GetSQLValueString($_POST['Title']));
$query0 = mysql_query($sql0, $link)or die(mysql_error());
$Title_Id = mysql_insert_id($link);
// ADD THE OBJECTS TO THE ARRAY
$arr[] = $Title_Id;
$sql1 = sprintf("insert into AIData ( Id, Path, Size, `Default`, TitleId, `Date`, PathThumb, DefaultProfilePic, ThumbViews, PicViews, ThumbViewsDate, PicViewsDate)
values ( null, '$consname', '$sizekb', 'Y', last_insert_id(), now(), '$consname2', 'N', '0', '0', now(), now())");
//GetSQLValueString($_POST['Default']));
//$query = mysql_query($sql)or die("The Administrative Team has been notified of this error.");
$query1 = mysql_query($sql1, $link)or die(mysql_error());
//} // end of if statement
} // end of outer if
// check if record set is not null
else
{
// insert into the title table the chosen album
$sql0 = sprintf("insert into AITitle (Id, Title, `Date`, AlbumId, DateCreated) values ( null, aes_encrypt(' ', '$PUkey'), now(), '$album_name_id', now())");
// GetSQLValueString($_POST['Title']));
$query0 = mysql_query($sql0, $link)or die(mysql_error());
$Title_Id = mysql_insert_id($link);
// ADD THE OBJECTS TO THE ARRAY
$arr[] = $Title_Id;
// $str_ids .= $row_source['Sfk'].',';
$sql1 = sprintf("insert into AIData ( Id, Path, Size, `Default`, TitleId, `Date`, PathThumb, DefaultProfilePic, ThumbViews, PicViews, ThumbViewsDate, PicViewsDate) values (null, '$consname', '$sizekb', 'N', last_insert_id(), now(), '$consname2', 'N', '0', '0', now(), now())");
//GetSQLValueString($_POST['Default']));
//$query = mysql_query($sql)or die("The Administrative Team has been notified of this error.");
$query1 = mysql_query($sql1, $link)or die(mysql_error());
}
if (!$copied) {
echo 'Copy unsuccessfull!';
$errors=1;
}else{
// the new thumbnail image will be placed in images/thumbs/ folder
$thumb_name=$consname2 ;
// call the function that will create the thumbnail. The function will get as parameters
//the image name, the thumbnail name and the width and height desired for the thumbnail
$thumb=make_thumb($consname,$thumb_name,WIDTH,HEIGHT);
$thumb=make_thumb($consname,$consname,WIDTH2,HEIGHT2);
}
}
}
}
}
// redirect to edit page
if(isset($_POST['Submit']) && !$errors) {
//$input = $arr;
//$output = array_slice($input, 1);
/*
foreach($input as $img_a) {
$img_sql[] = "'" . $img_a . "'";
}
$matrix = implode(',',$img_sql);
*/
//$matrix = NULL;
foreach($arr as $img_a)
{
$matrix .= "'" . mysql_real_escape_string($img_a) . "',";
}
$matrix = rtrim($matrix, ",");
//print_r($matrix);
//echo $value ,'this is the array for the whole loop! <br />';
$_SESSION['Image_String_Id'] = $matrix;
//echo $matrix ,'this is the array! <br />';
/*echo "Thumbnail created Successfully!";
echo '<img src="'.$thumb_name.'">';
echo '<br />';
echo "Imaged Uploaded Successfully!";
echo '<img src="'.$consname.'">';
echo '<a href="./manage_pictures.php?Album_Id=' ."$AlbumName_Id". '"/>Go to Manage Uploaded Photo Gallary</a>';
*/
//foreach($arr as $key=>$value){
$rowsPerPage = 20;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query_PicturesEdit0 = "SELECT a.Id as aId, c.Id as cId, c.Date as PicDate, aes_decrypt(c.Title, '$PUkey') as Title, d.Id as dId, d.Path as Picture, d.PathThumb, d.`Default` as DefaultPic, d.DefaultProfilePic as DefaultPP, d.PicThumbSize FROM ASAlbums a, ASManyAlbums b, ASTitle c, ASData d WHERE b.AlbumId=a.Id and c.AlbumId=b.AlbumId and c.Id=d.TitleId and b.UserId='$UserId' and a.Id ='$AlbumName_Id' and c.Id in ($matrix)" . " LIMIT $offset, $rowsPerPage";
/* ********************************************************** */
$result = @mysql_query($query_PicturesEdit0, $Pictures) or die(mysql_error()) ; // query to friends data set
$num = mysql_num_rows($result) ; // get row count
$_SESSION['num'] = $num;
$thumbcols = 5 ; // column count
// create the columns based on row count 5 columns per row
$thumbrows = 1+ round($num / $thumbcols);
// do {
echo '<form id="form1" name="form1" method="POST" action="' ."$editFormAction". '">';
echo '<table border="1" align="left" width="100%" cellpadding="0" cellspacing="0">' ;
// check record set for values
if(empty($num)) {
echo 'Must upload pictures to your account. <a href="./add_photo.php">Picture Upload</a>';
}
//if(!empty($num)) {
//echo '<tr><br />Check Off Pictures to Delete: <input type="submit" name="delete" value="Delete" id="delete"/></tr><br /><br />';
//} // closing of record count
//create function for table layout
function display_table() {
// create global variables
global $num, $result, $thumbrows, $thumbcols ;
// for loop for row counter
for ($r=1; $r<=$thumbrows; $r++) {
echo '<tr align="center" valign="baseline">' ;
// for loop for the columns
for ($c=1; $c<=$thumbcols; $c++) {
echo '<td align="center" valign="baseline">';
// get array from the query
$row = @mysql_fetch_array($result) ;
$dId = $row['dId'] ;
$cId = $row['cId'] ;
$aId = $row['aId'] ;
$Path = $row['PathThumb'] ;
$Name = $row['Title'] ;
$PicDate = $row['PicDate'];
$DefaultPic = $row['DefaultPic'];
$DefaultPP = $row['DefaultPP'];
$PathThumb1 = $row['PathThumb'];
$PicThumbSize = $row['PicThumbSize'];
// check to see if path is not null
if (!empty($Path)) {
echo "<br />" ; echo '<a href="../pictures/picture_edit.php?Album_Id=' ."$aId". '&PicTitleId=' ."$cId". '&AlbumPicId=' ."$dId". '"><img src="' . "$PathThumb1" . '" height="120" width="120" align="middle" border="1" /></a>';
echo '<br /><br />' ;
echo 'Title:' . '<input type="text" name="Title[]" id="Title" value="' ."$Name". '"/>' . '<br />';
echo "<br />";
echo 'Date: ' . '<input type="text" name="Date0[]" id="Date0" value="' ."$PicDate". '"/>' . '<br />';
echo '<br />';
echo 'Default Pic: ';
// <input '//. (!(strcmp("$DefaultPic","Y"))?'checked="checked"':'').' type="checkbox" name="Default" id="Default" value="" />' . '<br />';
if($DefaultPic == 'Y')
{
echo '<input type="checkbox" name="Default0[]" id="Default0" value="" checked="checked" />';
}
else
{
echo '<input type="checkbox" name="Default0[]" id="Default0" value="" />';
}
echo 'DefaultProfilePic:';
//<input '//. (!(strcmp("$DefaultPP","Y"))?'checked="checked"':'').' type="checkbox" name="DefaultProfilePic" id="DefaultProfilePic" value="" />' . '<br />';
if($DefaultPP == 'Y')
{
echo '<input type="checkbox" name="DefaultProfilePic[]" id="DefaultProfilePic" value="" checked="checked" />';
}
else
{
echo '<input type="checkbox" name="DefaultProfilePic[]" id="DefaultProfilePic" value="" />';
}
echo "<br />";
$picthumbsize = filesize($PathThumb1);
echo '<input type="hidden" id="PicThumbSize" name="PicThumbSize[]" value="' ."$picthumbsize" . '"/>';
echo '<input type="hidden" id="TitleId" name="TitleId[]" value="' ."$cId". '" />';
echo "<br />";
} // closing path images
else {
echo ' ' ;
} //closing space
echo '</td>' ;
} // closing the rows loop
echo '</tr>' ;
} //closing the row loop
} // closing the outer loop
// display the table
display_table() ;
// <?php } while ($row_Friends = mysql_fetch_assoc($Friends));
echo '<tr><td><input type="submit" name="Submit" value="Submit" /></td></tr>';
echo '</table>' ; // ending the table
echo '<input type="hidden" name="MM_update" value="form1" />' ;
echo '</form>'; // end of form
$_SESSION['Title_Name'] = $_POST['Title'];
$_SESSION['Date0'] = $_POST['Date0'];
// getting the navigation pages
$numrows = $totalRows_PicturesEdit;
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= ' <a href="' ."$self". '?page=' ."$page". '&Album_Id=' ."$Album_Id". '&FriendId=' ."$UserId". '">' ."$page". '</a> ';
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = ' <a href="' ."$self". '?page=' ."$page". '&Album_Id=' ."$Album_Id". '&FriendId=' ."$UserId". '">[Prev]</a> ';
$first = ' <a href="' ."$self". '?page=1&Album_Id=' ."$Album_Id". '&FriendId=' ."$UserId". '">[First Page]</a> ';
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = ' <a href="' ."$self". '?page=' ."$page". '&Album_Id=' ."$Album_Id". '&FriendId=' ."$UserId". '">[Next]</a> ';
$last = ' <a href="' ."$self". '?page=' ."$maxPage". '&Album_Id=' ."$Album_Id". '&FriendId=' ."$UserId". '">[Last Page]</a> ';
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo '<p align="center">'; echo $first . $prev . $nav . $next . $last; echo '</p>';
// select image for editing
// echo "<img src='"."$value"."' alt='"."$value"."'>";
//}
} // end of main function
?>
<p> </p>
<!-- end #mainContent --></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<div id="footer">
<p align="center"><a href="../index.php">Home</a> <a href="../browse/browse.php">Browse</a> <a href="../extras.php">Extras</a> <a href="../aboutus.php">About Us</a> <a href="../tos.php">ToS</a> <a href="../privacy.php">Privacy</a>
</p>
<p align="center"><label><font size="-2">This Site and Content per <a href="../tos.php">ToS</a> is Property of Only1Wizard.com </font></label></p>
<p> </p>
<!-- end #footer --></div>
<!-- end #container --></div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>
<?php
mysql_free_result($AlbumsList);
mysql_free_result($albumCheck);
?>
ASKER
here is the database tables:
mysql> desc aititle;
+-------------+----------- ---------- +------+-- ---+------ ---+------ -+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------- ---------- +------+-- ---+------ ---+------ -+
| Id | bigint(20) unsigned | NO | | 0 | |
| Title | longblob | YES | | NULL | |
| Date | date | NO | | NULL | |
| AlbumId | bigint(20) unsigned | NO | | NULL | |
| DateCreated | datetime | NO | | NULL | |
+-------------+----------- ---------- +------+-- ---+------ ---+------ -+
5 rows in set (0.04 sec)
mysql> desc aidata;
+-------------------+----- ---------- ------+--- ---+-----+ ---------+ -------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+----- ---------- ------+--- ---+-----+ ---------+ -------+
| Id | bigint(20) unsigned | NO | | 0 | |
| Path | longblob | NO | | NULL | |
| Size | varchar(45) | NO | | NULL | |
| Default | char(1) | NO | | N | |
| TitleId | bigint(20) unsigned | NO | | NULL | |
| Date | datetime | NO | | NULL | |
| PathThumb | longblob | NO | | NULL | |
| DefaultProfilePic | char(1) | NO | | N | |
| PicThumbSize | varchar(45) | NO | | NULL | |
| ThumbViews | varchar(45) | YES | | 0 | |
| PicViews | varchar(45) | YES | | 0 | |
| ThumbViewsDate | date | YES | | NULL | |
| PicViewsDate | date | YES | | NULL | |
+-------------------+----- ---------- ------+--- ---+-----+ ---------+ -------+
13 rows in set (0.11 sec)
thanks in advance for your help!
mysql> desc aititle;
+-------------+-----------
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------
| Id | bigint(20) unsigned | NO | | 0 | |
| Title | longblob | YES | | NULL | |
| Date | date | NO | | NULL | |
| AlbumId | bigint(20) unsigned | NO | | NULL | |
| DateCreated | datetime | NO | | NULL | |
+-------------+-----------
5 rows in set (0.04 sec)
mysql> desc aidata;
+-------------------+-----
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----
| Id | bigint(20) unsigned | NO | | 0 | |
| Path | longblob | NO | | NULL | |
| Size | varchar(45) | NO | | NULL | |
| Default | char(1) | NO | | N | |
| TitleId | bigint(20) unsigned | NO | | NULL | |
| Date | datetime | NO | | NULL | |
| PathThumb | longblob | NO | | NULL | |
| DefaultProfilePic | char(1) | NO | | N | |
| PicThumbSize | varchar(45) | NO | | NULL | |
| ThumbViews | varchar(45) | YES | | 0 | |
| PicViews | varchar(45) | YES | | 0 | |
| ThumbViewsDate | date | YES | | NULL | |
| PicViewsDate | date | YES | | NULL | |
+-------------------+-----
13 rows in set (0.11 sec)
thanks in advance for your help!
Thanks. Your actual code looks significantly different than the fake stuff.
I found this. In your code on line 74 you have this statement:
which is using sprintf with two arguments and no conversion specifications. Also, in that same statement it appears that the password in the aes_encrypt() is undefined.
You have these near the beginning of your code:
Are these session variables set from another page? I see where some of them are set later on in the code and some of them with $_POST information from the form. But this code will run through once to display your form, and these session variables won't be set, then after you submit your form the code starts over initializing your variables from undefined $_SESSION variables. They don't get set until after these lines are executed.
I would venture to say this is at least part of your problem.
I do have to apologize, but I have been up all night. I have to go to bed now. If you are still struggling with this when I get up, I will be more than happy to try and assist you.
I found this. In your code on line 74 you have this statement:
$updateSQL = sprintf("UPDATE AITitle SET Title=aes_encrypt('$Title_Name', '$PUkey'), `Date`='$Date0', AlbumId='$AlbumName_Id', DateCreated=now() WHERE Id=$NetId", GetSQLValueString($_POST['Title'.$w][$NetId], "text"),
GetSQLValueString($_POST['Date0'.$w][$NetId], "date"));
//GetSQLValueString($_POST['TitleId'.$w][$NetId], "int"));
which is using sprintf with two arguments and no conversion specifications. Also, in that same statement it appears that the password in the aes_encrypt() is undefined.
You have these near the beginning of your code:
$Net = explode(',' , $_SESSION['Image_String_Id']);
$Row_Count = $_SESSION['num'];
// table variables
$Title_Name = $_SESSION['Title_Name'];
$Date0 = $_SESSION['Date0'];
Are these session variables set from another page? I see where some of them are set later on in the code and some of them with $_POST information from the form. But this code will run through once to display your form, and these session variables won't be set, then after you submit your form the code starts over initializing your variables from undefined $_SESSION variables. They don't get set until after these lines are executed.
I would venture to say this is at least part of your problem.
I do have to apologize, but I have been up all night. I have to go to bed now. If you are still struggling with this when I get up, I will be more than happy to try and assist you.
ASKER
no problem thank u,
the password for aes_encrypt is defined in another file.
$net is a variable from a session array of thats on this page on or about line 657.
$row_count is a session that is in a function along with title_name and date0
i was trying out to see if that would work as a session to retrive those values through session since i wasn't getting them through post. i thought maybe the function was preventing them because in the var_dump($array) it shows all variables there but when it gets them in the query a couple of them is not their. and i don't know where to go from here to debug.
thanks in advance for your help!
the password for aes_encrypt is defined in another file.
$net is a variable from a session array of thats on this page on or about line 657.
$row_count is a session that is in a function along with title_name and date0
i was trying out to see if that would work as a session to retrive those values through session since i wasn't getting them through post. i thought maybe the function was preventing them because in the var_dump($array) it shows all variables there but when it gets them in the query a couple of them is not their. and i don't know where to go from here to debug.
thanks in advance for your help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question seems to be wandering away from the original issue, so I will sign off on it now. I urge you to get this book and study it, instead of trying to learn PHP by reading Dreamweaver code. Dreamweaver was never written with the intent of creating a set of learning examples, and frankly, it contains some of the worst examples of PHP code I have ever seen. The SitePoint book, on the other hand, is full of excellent explanation and correspondingly excellent examples.
From Sitepoint, with love:
http://www.sitepoint.com/books/phpmysql4/
Best of luck. Over and out, ~Ray
From Sitepoint, with love:
http://www.sitepoint.com/books/phpmysql4/
Best of luck. Over and out, ~Ray
ASKER
thanks for your help, i have learned from it.
Good luck. I think you will need it. And buy that book as soon as you can!! ~Ray
when i echo the sql query to see what was captured it comes back as null?
Are you getting an error? Is your database not updating?
If you run your query through the following code, do you get an error?
Open in new window