[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Mysql set to default for NULL

PHP upload.

My code if(array_key_exists('uploadNewFeatures', $_POST)) {
            if ($ID != "" && $ID != "new") {
                        $query = "UPDATE psh_communities SET features = '" . $_FILES['newFeatures']['name'] . "' WHERE ID = $ID";
                        $result = mysql_query($query);
                        move_uploaded_file($_FILES['newFeatures']['tmp_name'], $uploadfile5);
            }
      }

In order for my code to work correctly and stop using NULL as my default i need to have it be  blank so it doesnt think there is a file in that location, therefor not creating links to nothing on my webpage. Is this something i  have to fix in my DB i am using Mysql 5 and php 5.

If anyone can help please let me  know
0
Jiggens
Asked:
Jiggens
  • 6
  • 5
1 Solution
 
Beverley PortlockCommented:
Yes  - alter the table as follows

ALTER psh_communities CHANGE features features VARCHAR(255) NOT NULL

You should alter the VARCHAR(255) to match your field's size and type.
0
 
Beverley PortlockCommented:
Grr..... should read

ALTER TABLE psh_communities CHANGE features features VARCHAR(255) NOT NULL

full syntax at http://dev.mysql.com/tech-resources/articles/mysql-cluster-50.html
0
 
JiggensAuthor Commented:
I tried it on features it works but than i tried it another row

ALTER TABLE psh_communities CHANGE brochure brochure VARCHAR(255) NOT NULL

and i get Data truncated for column 'brochure' at row2  

Query could not execute
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
Beverley PortlockCommented:
Is "Brochure" a VARCHAR or a TEXT or an INT, etc etc?

Change the data type to match

0
 
JiggensAuthor Commented:
ITS A VARCHAR AS WELL
0
 
Beverley PortlockCommented:
In that case it is likely caused by having rows with NULLs and they should be cleared. It is usually a warning message displayed with SHOW WARNINGS. How does the data look? If you dump the table definition, does it read correctly for NOT NULL on that column?

0
 
JiggensAuthor Commented:
no, it already has not null in its place so your saying i should clear the nulls first?
0
 
Beverley PortlockCommented:
No - I'm saying that if the ALTER TABLE ran correctly, that message was the NULLs being cleared out. Remember that to databases "Truncate" means "Empty"

The key things here are

1) is the table definition now the way you wanted it?
2) is the data in the respective columns now NULL free?
0
 
JiggensAuthor Commented:
no there not
0
 
Beverley PortlockCommented:
Can you be more forthcoming? I can't tell what's wrong from just 3 words. Can you dump the table definition out so that I can at least see what you're attempting to work with?
0
 
JiggensAuthor Commented:
Thanks for all the help, i figured it out since the records already had the default as Null it was allowing me to change it i deleted the default null and replaced it with my own Null and it works now.

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now