Here is the code: ProductName varchar(50) NOT NULL default '', The problem is people can still type in heaps of characters after the "50". I would like it to be so they can't type anymore after the "50". How do I do this? Thanks for helping.
I should have mentioned sorry that I am editing from the database, as the script has been installed and the changes need to be made to the install file. So that being said when I go to edit the table "ProductName" I have many options in the "Type" dropdown box, such as varchar, tinyint, text etc. Do I just select one of these options to change it from varchar?
That is how it is currently, and it still allows people to type in more than 50, but when they publish it cuts off to 50.
They can type in as many characters as they want in a textarea (unless you give it the max length attribute)...but once you submit it to a database field that is varchar(50) the text will get cut off at 50. If you want max fields in the textarea AND the database field, set it to text instead of a varchar. Varchar can only be set up to 255. Hope this helps.
You can't do this in PHP (which is server-side), you need to do this with JavaScript (client-side). And it hasn't nothing to do with SQL either, as you want to limit the *user input* (which happens in the browser), right? Have a look here: http://javascript.internet.com/forms/limit-textarea.html You might want to use a "text" input field, it's easier to control the max input length (just add the attribute: "maxlength='50'")
I did try setting it as text but it made no difference. I think you are right no one seems to have an answer using the database. so which file to edit LOL I guess I will find it eventually. Thanks for the advice mate
Change your textarea code to this <input type='text' maxlength='50'> Nobody can type more than 50 characters in to that box now. Is this what you want?
Because I am dealing with php and the way this code is written for this particular script I don't think that is possible to do it, or should I say not possible with the file I am currently looking at which is the install file. I am sure I can do it with another file but for me the problem is knowing which file and where/how to add the code. Here is the install file: <? require_once("conn.php"); $q1 = "DROP TABLE IF EXISTS class_admin"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_admin ( AdminID int(10) NOT NULL auto_increment, username varchar(50) NOT NULL default '', password varchar(50) NOT NULL default '', PRIMARY KEY (AdminID))"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_admin VALUES (1, 'admin', 'admin')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_banners"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_banners ( BannerID int(10) NOT NULL auto_increment, BannerFile text NOT NULL, BannerAlt varchar(255) NOT NULL default '', BannerURL text NOT NULL, PRIMARY KEY (BannerID))"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_catalog"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_catalog ( ProductID int(10) NOT NULL auto_increment, MemberID int(10) NOT NULL default '0', ProductType varchar(10) NOT NULL default '', url varchar(255) NOT NULL default '', CategoryID int(10) NOT NULL default '0', ProductName varchar(50) NOT NULL default '', Description text NOT NULL, images text NOT NULL, Price float(10,2) NOT NULL default '0.00', views int(10) NOT NULL default '0', DatePosted int(10) NOT NULL default '0', DateExp int(10) NOT NULL default '0', FeaturedStatus int(1) not null default '0', PRIMARY KEY (ProductID))"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_categories"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_categories ( CategoryID int(10) NOT NULL auto_increment, CategoryName varchar(255) NOT NULL default '', PRIMARY KEY (CategoryID), UNIQUE KEY CategoryName(CategoryName)) "; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (2, 'Art / Hobbies')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (3, 'Auction / Classifields')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (4, 'Auto')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (5, 'Beauty / Women')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (6, 'Broadcast')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (7, 'Business')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (8, 'Career / Jobs')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (9, 'Chat / Mail')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (10, 'Children / Teens')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (11, 'Commerce / Retail')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (12, 'Computers / Tech')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (13, 'Education / Reference')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (14, 'Entertainment')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (15, 'Family')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (16, 'Finance')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (17, 'Gambling / Prizes')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (18, 'Hardware')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (19, 'Health / Medecine')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (20, 'Home / Garden')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (21, 'Humor')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (22, 'Industries')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (23, 'International')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (24, 'Internet')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (25, 'Legal')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (26, 'Music / MP3')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (27, 'News / World')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (28, 'Personals / Love')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (29, 'Portals / Search')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (30, 'Real Estate')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (31, 'Regional')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (32, 'Religion / Spirit')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (33, 'Sex / Adult')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (34, 'Sports')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_categories VALUES (35, 'Travel')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_members"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_members ( MemberID int(10) NOT NULL auto_increment, username varchar(50) NOT NULL default '', password varchar(50) NOT NULL default '', FirstName varchar(100) NOT NULL default '', LastName varchar(100) NOT NULL default '', Address varchar(255) NOT NULL default '', City varchar(255) NOT NULL default '', State varchar(255) NOT NULL default '', ZipCode varchar(25) NOT NULL default '', Country varchar(255) NOT NULL default '', AlternatePhone varchar(50) NOT NULL default '', Fax varchar(50) NOT NULL default '', email varchar(150) NOT NULL default '', Phone varchar(50) NOT NULL default '', StandardAds int(5) NOT NULL default '0', FeaturedAds int(5) NOT NULL default '0', ExpDate int(10) NOT NULL default '0', notified char(1) NOT NULL default 'n', AccountStatus varchar(10) NOT NULL default 'inactive', RegDate int(10) NOT NULL default '0', news char(1) NOT NULL default 'y', format varchar(10) NOT NULL default 'plain', PRIMARY KEY (MemberID), UNIQUE KEY username(username))"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_prices"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_prices ( PriceID int(10) NOT NULL auto_increment, ads int(5) NOT NULL default '0', days int(5) NOT NULL default '0', price float(10,2) NOT NULL default '0.00', PriorityLevel int(1) NOT NULL default '0', PRIMARY KEY (PriceID))"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO `class_prices` VALUES (1, 1, 7, '19.95', 1)"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_prices VALUES (2, 1, 7, '2.95', 0)"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_prices VALUES (3, 1, 14, '3.95', 0)"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_prices VALUES (4, 1, 30, '4.95', 0)"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_prices VALUES (5, 1, 30, '29.95', 1)"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO class_prices VALUES (6, 1, 14, '24.95', 1)"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_priority"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_priority"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "DROP TABLE IF EXISTS class_settings"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "CREATE TABLE class_settings ( id int(1) NOT NULL default '0', SiteTitle text NOT NULL, SiteKeywords text NOT NULL, SiteDesc text NOT NULL, ContactEmail varchar(150) NOT NULL default '', PayPalEmail varchar(150) NOT NULL default '', SellerID varchar(10) NOT NULL default '', terms text NOT NULL, testimonials text NOT NULL, message text NOT NULL, sp_vendor_email varchar(255) NOT NULL default '', sp_payee_email varchar(255) NOT NULL default '', sp_secret_code varchar(255) NOT NULL default '', banner_price varchar(10) NOT NULL default '', news_price varchar(10) NOT NULL default '')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); $q1 = "INSERT INTO `class_settings` VALUES (1, 'My Classifieds', 'My Classifieds', 'classifieds, sell, buy', 'neo@cyberia.ca', 'neo@cyberia.ca', '', '<p><strong>Terms of Use</strong></p>\r\n1. Use of this website is subject to the following terms and all applicable laws\; by accessing and browsing this website, you accept, without limitation or qualification, these terms. If you do not agree with any of the terms, please do not use the website. <p>2. Exclusion of Warranties. We make no representation or warranty regarding the functionality or condition of this website, its suitability for use, or that its use will be uninterrupted or error-free. ALL MATERIAL OR INFORMATION ON THIS WEBSITE IS PROVIDED TO YOU AS IS WITHOUT WARRANTIES OF ANY KIND. THIS WEBSITE DISCLAIMS ALL WARRANTIES OR CONDITIONS, WRITTEN OR ORAL, STATUTORY, EXPRESSED OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OR CONDITIONS OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. These exclusions are in addition to any specific exclusion otherwise provided in these terms and conditions. To the extent that the jurisdiction to which you are subject does not allow exclusion of certain warranties, such exclusions which are not permitted do not apply.</p><p>3. Limitation of Liability. THIS WEBSITE WILL NOT BE LIABLE FOR ANY DAMAGES, EITHER DIRECT OR INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL, FOR USE OF OR INABILITY TO USE MATERIAL, PRODUCTS OR SERVICES OF ANY KIND, DELAY OF TOTAL OR PARTIAL DELIVERY, TERMINATION OF RIGHTS OR LOSS OF PROFITS, DATA, BUSINESS OR GOODWILL, WHETHER ON A CONTRACTUAL OR EXTRACONTRACTUAL BASIS, OR TO PROVIDE INDEMNIFICATION OR ANY OTHER REMEDY TO YOU OR ANY THIRD PARTY. Your sole and exclusive remedy is to discontinue using and accessing this website. To the extent that the jurisdiction to which you are subject does not allow any part of such limitation, such part does not apply.</p><p>4. Links. Links and references to other websites are provided as a convenience only. This website has not reviewed and does not expressly or implicitly endorse other websites or any information or material, or the accessibility thereof, via such links, and does not assume any responsibility for any such other websites, information or material posted thereon, or products or services offered thereon.</p><p>5. Accuracy of Information. While this website tries to update the information or materials on this website as often as possible, no assurance is given that information or material on this website is up-to-date, accurate, error-free or complete.</p><p>6. Damage to Others. You agree not to introduce to or through this website any information or materials which may be harmful to others. Among other things, you agree not to include, knowingly or otherwise, any error or defect in materials or information which may, among other things, be a libel, slander, defamation or obscenity, or promote hatred or otherwise give rise to a criminal offence or civil liability on the part of any person or entity.</p><p>7. Changes to Terms. This website may modify, alter or otherwise update the terms applicable to this website from time to time without notice, and you agree to be bound by such terms as are in effect at the time at which you access this website.</p>', '<p>I never realised how easy it was to sell my unwanted stuff. With a few clicks \r\n everything was SOLD!. Thanks guys.<br>\r\n - David Smithson</p>\r\n<p>Buying was a snap. I was put in contact with the seller who closed the deal \r\n with me right away. Excellent!<br>\r\n - Lori Harris</p>\r\n', '', 'neo@cyberia.ca', 'neo@cyberia.ca', 'secretphrase', '12.95', '5.95')"; mysql_query($q1) or die(mysql_error()." at row ".__LINE__); echo "<br><br><br><center><font face=verdana size=2 color=black><b>The database tabes was installed successfully!<br><br>Delete this file from your server!</b></font>"; ?> PHP:
This is your MySQL install file. What the others are trying to say - what you want can be done via php (check if the passed value is >50 and truncate it) and/or HTML (the code should be in the file where the value is inserted - index.php, contacts.php etc. ) If you share your url we might be able to help you more.
Yeah I understand I need to edit a "index" file or something, here is the url, http://jead.net when making a listing I want to keep the listing title to 50 char and the description to 255 char max so people don't get confused thinking they have entered a nice ad and then to have it cut off, so they know they need to make it smaller description/title.