Jump to content

character limit


spanner206
Go to solution Solved by Ch0cu3r,

Recommended Posts

another beginners question from yours truly but i was just wondering how i would code a character limit on one of my fields iv been around the internet but i cant find what i need cause i usually come up with the same error code each time. if anyone knows what to do that would be great, hears the code iv been using.

<?php
$con = mysqli_connect("localhost","root","","nib");
// Check connection
if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// define variables and set to empty values

$companyname = $firstname = $address1 = $address2 = $area = $city = $postcode = $email = $website = $clubphone = $homephone = $mobilephone = $typeofbusiness = $renewaldate = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
 $errors = array();
 if (empty($_POST["companyname"]))
{
    $errors['companyname'] = "Please Enter Your companyname";
}
<input type='text' name='keywords' size='60' value='companyname' maxlength='10' /> 
elseif(strpos($_POST['companyname'], '/') !== false)
{
    $errors['companyname'] = 'Cannot use /';
}
elseif(strpos($_POST['companyname'], 'The') !== false)
{
    $errors['companyname'] = 'Company Names cant start with The';
}
elseif(strpos($_POST['companyname'], 'the') !== false)
{
    $errors['companyname'] = 'Company Names cant start with the';
}
elseif(strpos($_POST['companyname'], 'THE') !== false)
{
    $errors['companyname'] = 'Company Names cant start with THE';
}
else
{
   $companyname = test_input($_POST["companyname"]);
}

and heres the error code ive been getting.

( ! ) Parse error: syntax error, unexpected '<' in C:\wamp\www\AddLeads\addeadstemplate.php on line 29

 

aswell as this if i remove this symbol i get one to do with the else if statement witch i kinda need.

again if anyone has a solution please get back to me soon as 

 

Link to comment
Share on other sites

  • Solution

This is HTML

<input type='text' name='keywords' size='60' value='companyname' maxlength='10' /> 

You cannot just dump that into your PHP code and expect it to work.

 

 

i was just wondering how i would code a character limit on one of my fields

I guess you want to make sure the company name is not more than 60 characters the PHP code would be

if(strlen($_POST['companyname'] > 60))
{
    // company name is greater than 60 characters
}

Code for validating the companyname field would be

if (empty($_POST["companyname"]))
{
    $errors['companyname'] = "Please Enter Your companyname";
}
elseif(strlen($_POST['companyname'] > 60))
{
    $errors['companyname'] = 'Company name must be less then 60 characters';
}
elseif(stripos($_POST['companyname'], 'the'))
{
    $errors['companyname'] = 'Company Names cant start with the';
}
else
{
    $companyname = test_input($_POST["companyname"]);
}
Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.