[SOLVED] Column 'photo' cannot be null

This is a discussion on "[SOLVED] Column 'photo' cannot be null" within the PHP Forum section. This forum, and the thread "[SOLVED] Column 'photo' cannot be null are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 27th, 2007, 15:20
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Column 'photo' cannot be null

Could anyone help me find a fix to this code error i keep getting in my PHP form code: "Column 'photo' cannot be null"

Its driving me mad, any help would be great!

The code below is off my submit form, it all works until i add the images upload section of the code and form,

Here is what i have manged so far:

Once the form is submit the data goes into the database & the image goes into the images file,

My problem is the name of the image is not going into the databse, really confusing me!




PHP: Select all

<?php require_once('Connections/dbsignup.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}
$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO customer (first_name, last_name, address, city, area, email, phone, user_name, password, work_location, agency_name, agency_number, skills, about_me, myspace_address, hotmail_yahoo_address, gender, age, height_one, height_two, build, eye_colour, hair_colour, desired_work, photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['first_name'], "text"),
                       
GetSQLValueString($_POST['last_name'], "text"),
                       
GetSQLValueString($_POST['address'], "text"),
                       
GetSQLValueString($_POST['city'], "text"),
                       
GetSQLValueString($_POST['area'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['phone'], "int"),
                       
GetSQLValueString($_POST['user_name'], "text"),
                       
GetSQLValueString($_POST['password'], "text"),
                       
GetSQLValueString($_POST['work_location'], "text"),
                       
GetSQLValueString($_POST['agency_name'], "text"),
                       
GetSQLValueString($_POST['agency_number'], "text"),
                       
GetSQLValueString($_POST['skills'], "text"),
                       
GetSQLValueString($_POST['about_me'], "text"),
                       
GetSQLValueString($_POST['myspace_address'], "text"),
                       
GetSQLValueString($_POST['hotmail_yahoo_address'], "text"),
                       
GetSQLValueString($_POST['gender'], "text"),
                       
GetSQLValueString($_POST['age'], "text"),
                       
GetSQLValueString($_POST['height_one'], "int"),
                       
GetSQLValueString($_POST['height_two'], "int"),
                       
GetSQLValueString($_POST['build'], "text"),
                       
GetSQLValueString($_POST['eye_colour'], "text"),
                       
GetSQLValueString($_POST['hair_colour'], "text"),
                       
GetSQLValueString($_POST['desired_work'], "text"),
                       
GetSQLValueString($_POST['photo'], "text"));
  
mysql_select_db($database_dbsignup$dbsignup);
  
$Result1 mysql_query($insertSQL$dbsignup) or die(mysql_error());
}
$con mysql_connect("localhost","root","longstand1");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }
 
mysql_select_db("dbsignup"$con);
 
 
if (!empty(
$_POST['button'])) 

 
 
    
$needStrip get_magic_quotes_gpc(); 
 
 
    
$fields = array(); 
 
 
 
 
$fields['select'] = array('type'        => 's',       
                               
'required'    => true,    
                               
'column'        => 'first_name'    
                               
); 
    
$fields['select2'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'last_name' 
                               
); 
    
$fields['select3'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'address' 
                               
); 
    
$fields['select4'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'city' 
                               
); 
    
$fields['select5'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'area' 
                               
); 
    
$fields['select6'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'email' 
                               
); 
    
$fields['select7'] = array('type'        => 'n'
                               
'required'    => true
                               
'column'        => 'phone' 
                               
); 
    
$fields['select8'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'user_name' 
                               
); 
    
$fields['select9'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'password' 
                               
); 
    
$fields['select10'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'work_location' 
                               
); 
    
$fields['select11'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'agency_name' 
                               
); 
    
$fields['select12'] = array('type'        => 'n'
                               
'required'    => true
                               
'column'        => 'agency_number' 
                               
); 
    
$fields['select13'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'skills' 
                               
); 
    
$fields['select14'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'about_me' 
                               
); 
    
$fields['select15'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'myspace_address' 
                               
); 
    
$fields['select16'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'hotmail_yahoo_address' 
                               
); 
    
$fields['select17'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'gender' 
                               
);
    
$fields['select18'] = array('type'        => 'n'
                               
'required'    => true
                               
'column'        => 'age' 
                               
);
    
$fields['select19'] = array('type'        => 'n'
                               
'required'    => true
                               
'column'        => 'height_one' 
                               
);
    
$fields['select20'] = array('type'        => 'n'
                               
'required'    => true
                               
'column'        => 'height_two' 
                               
);
   
$fields['select21'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'build' 
                               
); 
   
$fields['select22'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'eye_colour' 
                               
);
   
$fields['select23'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'hair_colour' 
                               
);
   
$fields['select24'] = array('type'        => 's'
                               
'required'    => true
                               
'column'        => 'desired_work' 
                               
);
 
 
 
    
$errors = array(); 
 
 
$cols ''
    
$vals ''
 
 foreach (
$fields as $field => $dets
    { 
 
        
$field trim($field); 
 
 
        if (
$dets['required'] && empty($_POST[$field])) { 
            
$errors[] = $field ' is a required field!'
            continue; 
        } 
 
 
        if (
$dets['type'] == 'n' && !is_numeric($_POST[$field])) { 
            
$errors[] = $field ' should be a number!'
            continue; 
        } 
 
 
        if (empty(
$_POST['field']) || count($errors)) 
            continue; 
 
 
 
 
        
$_POST[$field] = $needStrip stripslashes($_POST[$field]) : $_POST[$field]; 
 
 
        
$_POST[$field] = mysql_real_escape_string($_POST[$field]); 
 
 
        if (!empty(
$cols)) { 
        
$cols .= ', '
        
$vals .= ', '
        } 
 
        
$cols .= $dets['column']; 
        
$vals .= $dets['type'] == 'n' && is_numeric($_POST[$field]) ? $_POST[$field] : "'{$_POST[$field]}'";  
 
    } 
 
 
 
    if (!
count($errors) && !empty($cols) && !empty($vals)) {        
 
 
        
$query "INSERT INTO customer($cols) VALUES($vals)"
 
 
         
mysql_select_db($database_dbsignup$dbsignup); 
        
$result mysql_query($query) or die(mysql_error()); 
 
 
        
$message "Cool you have been inserted as " mysql_insert_id(); // The insert ID 
 
    
}  else {  
 
 
        
$message '<strong>The following errors are screwing things up!</strong> 
                    <ol>'

 
        foreach (
$errors as $err)  
            
$message .= '<li>' $err '</li>'
 
        
$message .= '</ol>'
   }
}    
//This is the directory where images will be saved 
$target "images2/"
$target $target basename$_FILES['photo']['name']);
 
//This gets all the other information from the form 
$pic=($_FILES['photo']['name']); 
// Connects to your Database 
mysql_connect("localhost""root""longstand1") or die(mysql_error()) ; 
mysql_select_db("dbsignup") or die(mysql_error()) ; 
//Writes the information to the database 
mysql_query("INSERT INTO `customer` VALUES ('$name')") ; 
//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 

//Tells you if its all ok 
echo "The file "basename$_FILES['uploadedfile']['name']). "has been uploaded, and your information has been added to the directory"

else { 
//Gives and error if its not 
echo "Sorry Dear Customer There Was A Problem Uploading The Photo."

 
?>


My html form:

HTML: Select all
?><!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>Signup Today</title>
<style type="text/css">
<!--

@import url("Drop down menu/Untitled-1.css");
 
@import url("Drop down menu/Untitled-4.css");

@import url("Drop down menu/Untitled-4.css");
body {
 background-image: url(images/Only4Stars%20background.png);
}td img {display: block;}
.style1 {
 font-family: Tahoma;
 font-style: italic;
 color: #FFFFFF;
}
.style2 {
 font-family: Tahoma;
 color: #FFFFFF;
}
.style3 {font-family: Tahoma; color: #FFFFFF; font-size: 12px; }td img {display: block;}
.style4 {font-family: Tahoma; color: #FFFFFF; font-weight: bold; }
td img {display: block;}td img {display: block;}
.style12 {
 font-family: Tahoma;
 font-size: 14px;
}
.style13 {
 font-family: Geneva, Arial, Helvetica, sans-serif;
 font-size: 14px;
 color: #000000;
}td img {display: block;}
.style14 { color: #000000;
 font-size: 12px;
 font-family: Tahoma;
}
 
 
 
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript" src="Drop down menu/mm_css_menu.js"></script>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onload="MM_preloadImages('Drop down menu/Untitled-1_r1_c1_f2.gif','Drop down menu/Untitled-1_r2_c1_f2.gif','Drop down menu/Untitled-1_r3_c1_f2.gif','Drop down menu/Untitled-1_r4_c1_f2.gif','Drop down menu/Untitled-1_r4_c3_f2.gif','Drop down menu/Untitled-1_r5_c2_f2.gif','Drop down menu/Untitled-1_r6_c1_f2.gif','Drop down menu/Untitled-1_r7_c1_f2.gif','Drop down menu/Untitled-1_r9_c1_f2.gif','Drop down menu/Untitled-1_r10_c1_f2.gif','Drop down menu/Untitled-1_r11_c1_f2.gif','Drop down menu/Untitled-1_r13_c1_f2.gif')">
<table width="944" height="2005" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="228"><table width="943" height="228" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="419" bgcolor="#EBE9ED"><div align="center">
          <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','421','height','242','src','animation/Main Logo/Menu','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','animation/Main Logo/Menu' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="421" height="242">
            <param name="movie" value="animation/Main Logo/Menu.swf" />
            <param name="quality" value="high" />
            <embed src="animation/Main Logo/Menu.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="421" height="242"></embed>
          </object>
        </noscript></div></td>
        <td width="266" bgcolor="#99FF00"><div align="center">
          <table width="250" height="228" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','251','height','237','src','animation/slide show 1/Movie1','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','animation/slide show 1/Movie1' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="251" height="237">
                <param name="movie" value="animation/slide show 1/Movie1.swf" />
                <param name="quality" value="high" />
                <embed src="animation/slide show 1/Movie1.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="251" height="237"></embed>
              </object></noscript></td>
            </tr>
          </table>
        </div></td>
        <td width="248" bgcolor="#99FF00"><div align="center">
          <table width="250" height="228" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','251','height','237','src','animation/slideshow 2/Movie1','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','animation/slideshow 2/Movie1' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="251" height="237">
                <param name="movie" value="animation/slideshow 2/Movie1.swf" />
                <param name="quality" value="high" />
                <embed src="animation/slideshow 2/Movie1.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="251" height="237"></embed>
              </object></noscript></td>
            </tr>
          </table>
        </div></td>
        <td width="10" bgcolor="#99FF00">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="94"><img name="" src="images/Photo Reel.png" width="945" height="125" alt="" /></td>
  </tr>
  <tr>
    <td height="1651" valign="top"><table width="944" height="1664" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="189" height="1651" valign="top" bgcolor="#990000"><div id="FWTableContainer1603953034">
          <table border="0" cellpadding="0" cellspacing="0" width="190">
            <!-- fwtable fwsrc="Untitled" fwpage="Page 1" fwbase="Untitled-1.gif" fwstyle="Dreamweaver" fwdocid = "1603953034" fwnested="0" -->
            <tr>
              <td><img src="Drop down menu/spacer.gif" width="36" height="1" border="0" alt="" /></td>
              <td><img src="Drop down menu/spacer.gif" width="81" height="1" border="0" alt="" /></td>
              <td><img src="Drop down menu/spacer.gif" width="73" height="1" border="0" alt="" /></td>
              <td><img src="Drop down menu/spacer.gif" width="1" height="1" border="0" alt="" /></td>
            </tr>
            <tr>
              <td colspan="3"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r1_c1','','Drop down menu/Untitled-1_r1_c1_f2.gif',1);"><img name="Untitled1_r1_c1" src="Drop down menu/Untitled-1_r1_c1.gif" width="190" height="34" border="0" id="Untitled1_r1_c1" alt="" /></a></td>
              <td><img src="Drop down menu/spacer.gif" width="1" height="34" border="0" alt="" /></td>
            </tr>
            <tr>
              <td colspan="3"><a href="about.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r2_c1','','Drop down menu/Untitled-1_r2_c1_f2.gif',1);"><img name="Untitled1_r2_c1" src="Drop down menu/Untitled-1_r2_c1.gif" width="190" height="34" border="0" id="Untitled1_r2_c1" alt="" /></a></td>
              <td><img src="Drop down menu/spacer.gif" width="1" height="34" border="0" alt="" /></td>
            </tr>
            <tr>
              <td colspan="3"><a href="javascript:;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r3_c1','','Drop down menu/Untitled-1_r3_c1_f2.gif','Untitled1_r4_c1','','Drop down menu/Untitled-1_r4_c1_f2.gif','Untitled1_r4_c3','','Drop down menu/Untitled-1_r4_c3_f2.gif','Untitled1_r5_c2','','Drop down menu/Untitled-1_r5_c2_f2.gif',1);"><img name="Untitled1_r3_c1" src="Drop down menu/Untitled-1_r3_c1.gif" width="190" height="12" border="0" id="Untitled1_r3_c1" alt="" /></a></td>
              <td><img src="Drop down menu/spacer.gif" width="1" height="12" border="0" alt="" /></td>
            </tr>
            <tr>
              <td rowspan="2"><a href="javascript:;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r3_c1','','Drop down menu/Untitled-1_r3_c1_f2.gif','Untitled1_r4_c1','','Drop down menu/Untitled-1_r4_c1_f2.gif','Untitled1_r4_c3','','Drop down menu/Untitled-1_r4_c3_f2.gif','Untitled1_r5_c2','','Drop down menu/Untitled-1_r5_c2_f2.gif',1);"><img name="Untitled1_r4_c1" src="Drop down menu/Untitled-1_r4_c1.gif" width="36" height="22" border="0" id="Untitled1_r4_c1" alt="" /></a></td>
              <td><a href="javascript:;" onmouseout="MM_menuStartTimeout(1000);" onmouseover="MM_menuShowMenu('MMMenuContainer1101183735_0', 'MMMenu1101183735_0',81,0,'Untitled1_r4_c2');"><img name="Untitled1_r4_c2" src="Drop down menu/Untitled-1_r4_c2.gif" width="81" height="13" border="0" id="Untitled1_r4_c2" alt="" /></a></td>
              <td rowspan="2"><a href="javascript:;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r3_c1','','Drop down menu/Untitled-1_r3_c1_f2.gif','Untitled1_r4_c1','','Drop down menu/Untitled-1_r4_c1_f2.gif','Untitled1_r4_c3','','Drop down menu/Untitled-1_r4_c3_f2.gif','Untitled1_r5_c2','','Drop down menu/Untitled-1_r5_c2_f2.gif',1);"><img name="Untitled1_r4_c3" src="Drop down menu/Untitled-1_r4_c3.gif" width="73" height="22" border="0" id="Untitled1_r4_c3" alt="" /></a></td>
              <td><img src="Drop down menu/spacer.gif" width="1" height="13" border="0" alt="" /></td>
            </tr>
            <tr>
              <td><a href="javascript:;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r3_c1','','Drop down menu/Untitled-1_r3_c1_f2.gif','Untitled1_r4_c1','','Drop down menu/Untitled-1_r4_c1_f2.gif','Untitled1_r4_c3','','Drop down menu/Untitled-1_r4_c3_f2.gif','Untitled1_r5_c2','','Drop down menu/Untitled-1_r5_c2_f2.gif',1);"><img name="Untitled1_r5_c2" src="Drop down menu/Untitled-1_r5_c2.gif" width="81" height="9" border="0" id="Untitled1_r5_c2" alt="" /></a></td>
              <td><img src="Drop down menu/spacer.gif" width="1" height="9" border="0" alt="" /></td>
            </tr>
            <tr>
              <td colspan="3"><a href="your_account.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Untitled1_r6_c1','','Drop down menu/Untitled-1_r6_c1_f2.gif',1);"><img name="Untitled1_r6_c1" src="Drop down menu/Untitled-1_r6_c1.gif" width="190" height="33" border="0" id="Untitled1_r6_c1" alt=