Sunday, March 28, 2010

php form field inserts return empty...

hello -

i've created a form that has multiple inserts. it inserts the data fine if i manually parse the data to it but when i use the form to test the inserts it errors out.

i've used echo $_post variable and the variable is their. but its not being inserted into the database.

it says that the string cannot be null?

where do i go from here for debugging?

thanks, in advance for your help!

theo werntz ii

php form field inserts return empty...

whatever string it says that can't be null either fill it in on your form or change the row to 'null' in phpMyAdmin If that doesn't work more details are required.

php form field inserts return empty...

I've tried entering data but it doesn't insert i've change the column type to longblob from varchar and it still doesnt insert.

here is my code: ignore the numbers and line ending with $

******************************************************************************** ******************************************************************************

?1 %26lt;?php require_once('Connections/upics.php'); ?%26gt;$
?2 %26lt;?php$
?3 if (!function_exists(''GetSQLValueString'')) {$
?4 function GetSQLValueString($theValue, $theType, $theDefinedValue = '''', $theNotDefinedValue = '''') $
?5 {$
?6 if (PHP_VERSION %26lt; 6) {$
?7 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;$
?8 }$
?9 $
10 $theValue = function_exists(''mysql_real_escape_string'') ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);$
11 $
12 switch ($theType) {$
13 case ''text'':$
14 $theValue = ($theValue != '''') ? ''''' . $theValue . ''''' : ''NULL'';$
15 break;?$
16 case ''long'':$
17 case ''int'':$
18 $theValue = ($theValue != '''') ? intval($theValue) : ''NULL'';$
19 break;$
20 case ''double'':$
21 $theValue = ($theValue != '''') ? doubleval($theValue) : ''NULL'';$
22 break;$
23 case ''date'':$
24 $theValue = ($theValue != '''') ? ''''' . $theValue . ''''' : ''NULL'';$
25 break;$
26 case ''defined'':$
27 $theValue = ($theValue != '''') ? $theDefinedValue : $theNotDefinedValue;$
28 break;$
29 }$
30 return $theValue;$
31 }$
32 }$
33 $
34 $
35 $uname=''guest'';$
36 $uname_id = '1' ;$
37 $pt=''pictures'';$
38 $picPath=''pt/img_0.gif''; $
39 $picSize=''1024'';$

40 $
41 $editFormAction = $_SERVER['PHP_SELF'];$
42 if (isset($_SERVER['QUERY_STRING'])) {$
43 $editFormAction .= ''?'' . htmlentities($_SERVER['QUERY_STRING']);$
44 }$
45 $
46 if ((isset($_POST[''MM_insert''])) %26amp;%26amp; ($_POST[''MM_insert''] == ''form1'')) {$
47 $
48 $insertSQL_0 = sprintf(''INSERT INTO album (album_id, album_nm, album_dt, album_pt) VALUES ( %s, %s, curdate(), '$pt')'',$
49?GetSQLValueString($_POST['album_id'], ''int''),$
50?GetSQLValueString($_POST['album_nm'], ''text''),$
51?GetSQLValueString($_POST['album_dt'], ''date''),$
52?GetSQLValueString($_POST['album_pt'], ''text''));$
53 $
54 $insertSQL_1 = sprintf(''insert into album_has_user (album_album_id, user_user_id, user_admin_id) values (last_insert_id(), '$uname_id', '$uname_id')'',$
55 GetSQLValueString($_POST['album_has_user'], ''int''),$
56 GetSQLValueString($_POST['user_user_id'], ''int''),$
57 GetSQLValueString($_POST['user_admin_id'], ''int''),$
58 $
59 $insertSQL_2 = sprintf(''insert into title (title_id, title_title, title_dt, album_album_id, title_memo) values (last_insert_id(), %s, curdate(), last_ins?ert_id(), %s)'',$
60 GetSQLValueString($_POST['title_id'], ''int''),$
61 GetSQLValueString($_POST['title_title'], ''text''),$
62 GetSQLValueString($_POST['title_dt'], ''date''),$
63 GetSQLValueString($_POST['album_album_id'], ''int''),$
64 GetSQLValueString($_POST['title_memo'], ''text''));$
65 $
66 $
67 $insertSQL_3 = sprintf(''insert into picture (picture_id, picture_dp, picture_sz, picture_df, title_title_id) values?(last_insert_id(), '$picPath', '$pic?Size', 'N', last_insert_id())'', $
68 GetSQLValueString($_POST['picture_id'], ''int''),$
69 GetSQLValueString($_POST['picture_dp'], ''text''),$
70 GetSQLValueString($_POST['picture_sz'], ''text''),$
71 GetSQLValueString($_POST['picture_df'], ''text''),$
72 GetSQLValueString($_POST['title_title_id'], ''int''));$
73 $
74 echo $_POST['title_title'];

75 $
76 //insert users album if null$
77 mysql_select_db($database_upics, $upics);$
78 $Result1 = mysql_query($insertSQL_0, $upics) or die(mysql_error());$
79 $
80 //insert users many data$
81 mysql_select_db($database_upics, $upics);$
82 $Result2 = mysql_query($insertSQL_1, $upics) or die(mysql_error());$
83 $
84 //insert users title and comments?$
85 mysql_select_db($database_upics, $upics);$
86 $Result3 = mysql_query($insertSQL_2, $upics) or die(mysql_error());$
87 $
88 //insert users picuter path$
89 mysql_select_db($database_upics, $upics);$
90 $Result4 = mysql_query($insertSQL_3, $upics) or die(mysql_error());?$
91 $
92 $insertGoTo = ''picture_edit.php'';$
93 if (isset($_SERVER['QUERY_STRING'])) {$
94 $insertGoTo .= (strpos($insertGoTo, '?')) ? ''%26amp;'' : ''?'';$
95 $insertGoTo .= $_SERVER['QUERY_STRING'];$
96 }$
97 header(sprintf(''Location: %s'', $insertGoTo));$
98 }$
99 ?%26gt;$
100 %26lt;!DOCTYPE html PUBLIC ''-//W3C//DTD XHTML 1.0 Transitional//EN'' ''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd''%26gt;$
101 %26lt;html xmlns=''http://www.w3.org/1999/xhtml''%26gt;$
102 %26lt;head%26gt;$
103 %26lt;meta http-equiv=''Content-Type'' content=''text/html; charset=utf-8'' /%26gt;$
104 %26lt;title%26gt;Untitled Document%26lt;/title%26gt;$
105 %26lt;/head%26gt;$
106 $
107 %26lt;body%26gt;$
108 %26lt;form action=''%26lt;?php echo $editFormAction; ?%26gt;'' method=''post'' name=''form1'' id=''form1''%26gt;$
109 %26lt;table align=''center''%26gt;$
110 %26lt;tr valign=''baseline''%26gt;$
111 %26lt;td nowrap=''nowrap'' align=''right''%26gt;Album Name:%26lt;/td%26gt;$
112 %26lt;td%26gt;%26lt;input type=''text'' name=''album_nm''?id=''album_nm'' value=''default'' size=''32'' /%26gt;%26lt;/td%26gt;$
113 %26lt;/tr%26gt;$

114 %26lt;tr valign=''baseline''%26gt;$
115 %26lt;td nowrap=''nowrap'' align=''center''%26gt;Title:%26lt;/td%26gt;$
116 %26lt;td%26gt;%26lt;input name=''title_title'' id=''title_title'' type=''text'' value='''' size=''32'' /%26gt;%26lt;/td%26gt;$
117 %26lt;/tr%26gt;$
118 %26lt;tr valign=''baseline''%26gt;$
119 %26lt;td nowrap=''nowrap'' align=''center''%26gt;Date:%26lt;/td%26gt;$
120 %26lt;td%26gt;%26lt;input name=''title_dt'' id=''title_dt'' type=''text'' value='''' size=''32'' /%26gt;%26lt;/td%26gt;$
121 %26lt;/tr%26gt;$
122 %26lt;tr valign=''baseline''%26gt;$
123 %26lt;td nowrap=''nowrap'' align=''center''%26gt;Comments:%26lt;/td%26gt;$
124 %26lt;td%26gt;%26lt;textarea name=''title_memo'' cols=''32'' id=''title_memo''%26gt;%26lt;/textarea%26gt;%26lt;/td%26gt;$
125 %26lt;/tr%26gt;$
126 %26lt;tr valign=''baseline''%26gt;$
127 %26lt;td nowrap=''nowrap'' align=''right''%26gt;?lt;/td%26gt;$
128 %26lt;td%26gt;%26lt;input type=''submit'' value=''Insert record'' /%26gt;%26lt;/td%26gt;$
129 %26lt;/tr%26gt;$
130 %26lt;/table%26gt;$
131 %26lt;input type=''hidden'' name=''album_id'' value='''' /%26gt;$
132 %26lt;input type=''hidden'' name=''album_dt'' value='''' /%26gt;$
133 %26lt;input type=''hidden'' name=''album_pt'' value='''' /%26gt;$
134 %26lt;input type=''hidden'' name=''MM_insert'' value=''form1'' /%26gt;$
135 %26lt;/form%26gt;$
136 %26lt;p%26gt;?lt;/p%26gt;$
137 %26lt;/body%26gt;$
138 %26lt;/html%26gt;$

******************************************************************************** ****************************************

this is echo:?this is the error:

default Column 'title' cannot be null

thanks in advance for you help

No comments:

Post a Comment