Pure PHP Upload 2 Support Product Page

This topic is locked
This topic was archived

"Column 'name' cannot be null"

Asked 02 Dec 2003 21:51:03
1
has this question
02 Dec 2003 21:51:03 Nick B posted:
I'm using MX2004 and want to upload an image and insert its filename into a database. Below is my table structure:

CREATE TABLE `test` (
`ID` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
PRIMARY KEY (`ID`)
)

And here is the code for the page:
<pre id=code><font face=courier size=2 id=code>&lt;?php require_once('Connections/Mazzis.php'); ?&gt;
&lt;?php require_once('ScriptLibrary/incPureUpload.php'); ?&gt;
&lt;?php
// Pure PHP Upload 2.1.2
if (isset($HTTP_GET_VARS['GP_upload'])) {
$ppu = new pureFileUpload();
$ppu-&gt;path = "fampics";
$ppu-&gt;extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu-&gt;formName = "form1";
$ppu-&gt;storeType = "path";
$ppu-&gt;sizeLimit = "2500";
$ppu-&gt;nameConflict = "uniq";
$ppu-&gt;requireUpload = "true";
$ppu-&gt;minWidth = "";
$ppu-&gt;minHeight = "";
$ppu-&gt;maxWidth = "";
$ppu-&gt;maxHeight = "";
$ppu-&gt;saveWidth = "";
$ppu-&gt;saveHeight = "";
$ppu-&gt;timeout = "600";
$ppu-&gt;progressBar = "";
$ppu-&gt;progressWidth = "";
$ppu-&gt;progressHeight = "";
$ppu-&gt;checkVersion("2.1.2";
$ppu-&gt;doUpload();
}
$GP_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
$GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING']."&GP_upload=true";
} else {
$GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
}
} else {
$GP_uploadAction .= "?"."GP_upload=true";
}

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 != "" ? "'" . date("Y-m-d",strtotime($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']);
}

if (isset($editFormAction)) {
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "&GP_upload=true";
}
} else {
$editFormAction .= "?GP_upload=true";
}
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO test (name) VALUES (%s)",
GetSQLValueString($_POST['name'], "text");

mysql_select_db($database_Mazzis, $Mazzis);
$Result1 = mysql_query($insertSQL, $Mazzis) or die(mysql_error());

$insertGoTo = "$PHP_SELF";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;script language='javascript' src='ScriptLibrary/incPureUpload.js'&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form action="&lt;?php echo $editFormAction; ?&gt;" method="post" enctype="multipart/form-data" name="form1" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,2500,'','','','','','');return document.MM_returnValue"&gt;
&lt;input name="name" type="file" id="name" onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,2500,'','','','','','')"&gt;
&lt;input type="submit" name="Submit" value="Submit"&gt;
&lt;input type="hidden" name="MM_insert" value="form1"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</font id=code></pre id=code>

When I run the page, which is located at www.mazzis.com/test.php

I always get the error: "Column 'name' cannot be null"

I've read through the tutorials many times and tried created new pages from scratch several times and am getting a little frustrated at this not working.

What am I doing wrong?

Thank you.

Replies

Replied 03 Dec 2003 11:58:04
03 Dec 2003 11:58:04 Patrick Woldberg replied:
The name column does not accept NULL values, if no file is uploaded this field contains a NULL value. You should allow NULL values to that column in the database or do some handcoding to replace the NULL value with an empty string or something.

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------
Replied 03 Dec 2003 20:43:08
03 Dec 2003 20:43:08 Nick B replied:
But when I do upload a file, that doesn't insert its filename into the table column "name". I thought that was the whole point behind the upload and insert tutorial, but I can't get it to work. What do I need to do? Thanks.
Replied 04 Dec 2003 11:40:00
04 Dec 2003 11:40:00 Patrick Woldberg replied:
OK, found the error. It is something we are working on and is because the insert behavior of Dreamweaver MX 2004 was changed. Change all $_POST into $HTTP_POST_VARS

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------
Replied 09 Dec 2003 11:54:49
09 Dec 2003 11:54:49 alessandro condorman replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
OK, found the error. It is something we are working on and is because the insert behavior of Dreamweaver MX 2004 was changed. Change all $_POST into $HTTP_POST_VARS

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

I have this problem, but if i change $_POST into $HTTP_POST_VARS the error remain: Column 'asd' cannot be null"

&lt;?php require_once('Connections/database.php'); ?&gt;
&lt;?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']);
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO asd (ASD) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['file'], "text");

mysql_select_db($database_database, $database);
$Result1 = mysql_query($insertSQL, $database) or die(mysql_error());
}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form action="&lt;?php echo $editFormAction; ?&gt;" name="form1" enctype="multipart/form-data" method="POST"&gt;
&lt;p&gt;
&lt;input type="file" name="file"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input type="submit" name="Submit" value="Submit"&gt;
&lt;/p&gt;

&lt;input type="hidden" name="MM_insert" value="form1"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


Edited by - condorman on 09 Dec 2003 11:55:07
Replied 06 Jan 2004 02:16:31
06 Jan 2004 02:16:31 Nick B replied:
Has this problem been fixed yet? Is there a new version of this extension that does this instead of me paying for an extension then having to hand code fix your work?
Replied 10 Jan 2004 02:59:09
10 Jan 2004 02:59:09 Theologos Fragopoulos replied:
I just changed the $_POST['column'] to $HTTP_POST_VARS['column'] and worked ok for me.
Replied 10 Jan 2004 07:03:25
10 Jan 2004 07:03:25 Nick B replied:
Yeah, but has the extension been updated? I purchased the extension to automate the process, not so I'd have to do a find and replace on the code the extension puts in.
Replied 14 Jan 2004 12:19:46
14 Jan 2004 12:19:46 Patrick Woldberg replied:
The new update is beta now and should fix it, won't take long untill release, just need to be sure that it workes fine.

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------
Replied 27 Jan 2004 21:09:54
27 Jan 2004 21:09:54 ERROR ERROR replied:
Hi.

Has this beta change made it to the commercial version yet?

Thanks
Tim
Replied 30 Jan 2004 02:10:26
30 Jan 2004 02:10:26 Donal o'sullivan replied:
I just got the php upload extension, and am in the process of getting it to work with my site organisation. All seems to be fine really so far (just me being stupid the odd time), and the info here has sorted my main problem.
On this topic though, you mention a new beta in the pipeline, but I don't understand the situation with product upgrades for existing users? Do we get free upgrades or not?

Otherwise, it's php-easy-tastic.

cheers
Replied 30 Jan 2004 10:35:52
30 Jan 2004 10:35:52 Martha Graham replied:
Once you have purchased the extension you are entitled to free updates.

Martha Graham
DMXzone manager
Replied 27 Jun 2004 16:53:00
27 Jun 2004 16:53:00 Eduardo Gomez replied:
Hi there,

Has an updated version been released yet?

In the record update page I created, I changed $_POST to $HTTP_POST_VARS for the column in question, and I succesfully uploaded an image.

However, if I return to the record update page and DON'T change the image (i.e., keep the image currently in the database), and hit the update button, when I come back again, it's deleted the image name from the database field. To keep the current image in the database, I have to reupload.

Is there a way to fix this?
Replied 29 Jul 2004 15:43:52
29 Jul 2004 15:43:52 Camillah Ringes replied:
For now this is the only way to overcome the problem.
Sorry for the inconvience we are working on it.

Regards,



--------------------------------------------------
Camillah Ringes
Support Team DMXzone.com
--------------------------------------------------
Replied 29 Jul 2004 19:18:13
29 Jul 2004 19:18:13 Nick B replied:
Only 7 and a half months later. At this rate, we should have an updated extension that we all paid for by.....November 2006?
Replied 09 Aug 2004 11:48:13
09 Aug 2004 11:48:13 Camillah Ringes replied:
We released the update last week.

--------------------------------------------------
Camillah Ringes
Support Team DMXzone.com
--------------------------------------------------

Reply to this topic