SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    0 Post(s)
    0 Thread(s)

    Validation issue

    Hi there,

    I thought i'd sorted my php validation out. however, if I enter the same name twice, i get a 'name already taken', which is fine. If I leave the name as-is, and correctly enter all other fields, the name is ignored, and the data inserted to the database. Meaning i now have 2 of the same name being input to the db.

    Can anyone help? I have inserted my form (html and php) below.

    PHP Code:
        <div id="container">

            <div id="header">    </div>
            <div id="navigation">
                    <li><a href="index.php">Home </a></li>
                    <li><a href="about.php"><img src=""> </a></li>
                    <li><a href="register.php">Register </a></li>
                    <li><a href="help.php">Help </a></li>
                    <li><a href="faq.php">FAQ </a></li>


            <div id="left_content">


            <div id="main_content">
                <h3> Hello and Welcome  </h3>

    function account_exists($column$value) {
    $accounts mysql_query('SELECT * FROM businesses WHERE ' $column ' = "' $value '"');

    $return = (mysql_num_rows($accounts) > 0) ? true false;


    $spam_check ZGF;

    //    Check Email Address courtesy of Dave Child:
    //    [url][/url]
    function check_email_address($email) {

        if (!
    ereg("^[^@]{1,64}@[^@]{1,255}$"$email)) return false;

    $email_array explode("@"$email);
    $local_array explode("."$email_array[0]);

        for (
    $i 0$i sizeof($local_array); $i++) {
            if (!
    ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$"$local_array[$i])) return false;

        if (!
    ereg("^\[?[0-9\.]+\]?$"$email_array[1])) {

    $domain_array explode("."$email_array[1]);

            if (
    sizeof($domain_array) < 2) return false;

            for (
    $i 0$i sizeof($domain_array); $i++) {
                if (!
    ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$"$domain_array[$i])) return false;




        if (isset(
    $_POST['submit'])) {
    $business_name = ( $_POST['business_name']);
    $category = ( $_POST['category']);
    $email = ( $_POST['email'] );
    $description = ( $_POST['description'] );
    $spam_check $_REQUEST['spam_check'];

        if (empty(
    $business_name)) {
    "<p class='form_text'>The Business Name is empty</p>";
         else if (
    account_exists('business_name'$business_name)) {
    "<p class='form_text'> Sorry, that Business Name is already registered";
        if (empty(
    $category)) {
    "<p class='form_text'>The Category is empty</p>";
    //    Email address checks
    if (empty($email)) {
    "<p class='form_text'>You must enter your email address</p>";
        } else if (!
    check_email_address($email)) {
    "<p class='form_text'>Your email address is invalid</p>";
        if (empty(
    $description)) {
    "<p class='form_text'>The Description is empty</p>";

        if (
    $spam_check !="ZGF") {
    "<p class='form_text'>Spam Check Failed</p>";
        else {
    mysql_query"INSERT INTO `businesses`(business_name,category,email,description) VALUES ('$business_name','$category','$email','$description')" ) or die( mysql_error() );

    //send email
    $business_name=stripslashes($_REQUEST['business_name']) ;
    $email=stripslashes($_REQUEST['email']) ;
    $category=stripslashes($_REQUEST['category']) ;
    $description=stripslashes($_REQUEST['description']) ;

    $email_message "Business Name: \n {$business_name} \n \n Email Address: \n {$email} \n \n  Category: \n {$category} \n \n Description: \n {$description}";

    mail('''Business Reg Submission'$email_message'From: '.$email."\r\n");


    "<p class='form_text_success'>Thanks, you have now been added to the directory.</p>";

    '<META HTTP-EQUIV="Refresh" Content="5; URL=thanks.php">'


                <div id="stylized" class="myform">    
                    <form  action="index.php" method="post">

                    <h1>Business Registration</h1>
                    <p>Please enter the form below to register your business with business-reg</p>
                    <label>Business Name
                    <span class="small">Add your business name</span>
                    <input type="text" name="business_name" id="business_name" value="<?php echo $business_name?>" />

                    <label> Category
                    <span class="small">Please add a category</span>
                    <select name="category" size="1" id="category">
                      <option value="accomodation">Accomodation</option>
                      <option value="accountancy">Accountancy</option>
                      <option value="accomodation">Accomodation</option>

                    <label>Business Email
                    <span class="small">Add a valid address</span>
                    <input type="text" name="email" id="email" value="<?php echo $email?>" />

                    <span class="small">Please describe your business</span>
                    <textarea cols="22" rows="10" id="description" name="description"><?php echo $description?></textarea>
                    <label>Spam Checker
                    <span class="small">Enter the last 3 characters</span>
                    <img src="">
                    <input type="text" name="spam_check" id="spam_check" />

                    <button type="submit" name="submit" id="submit"></button>
                    <div class="spacer"></div>



    Last edited by ScallioXTX; Mar 24, 2011 at 08:20. Reason: Wrapped code in [php][/php]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts