Results 1 to 5 of 5

Thread: I want to add a error code to this

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    I want to add a error code to this

    I want to add a code to this which will the make sure the user has added in a first name in the box and if not kick them out... i've tried serveral but none have worked... any ideas

    PHP Code:

    <?php 

    $check 
    "select id from members where username = '".$_POST['username']."';"
    $qry mysql_query($check) or die ("Could not match data because ".mysql_error());
    $num_rows mysql_num_rows($qry); 
    if (
    $num_rows != 0) { 
    echo 
    "Sorry, the username $username is already taken. Please go back and try another.<br>";


    } else { 


    $result mysql_query("insert into members (`id`,`username`,`firstname`,`lastname`,`dob`,`address`,`city`,`country`,`phone`,`email`,`password`,`nz_mailing`,`active`,`warriors_mailing`,`bcc_mailing`,`level`) values ('', '".$_POST['username']."','$firstname','$lastname','$dob','$address','$city','$country','$phone','$email','".$_POST['password']."','$nz_mailing','$active','$warriors_mailing','$bcc_mailing','$level')")
    or die(
    "Could not insert data because ".mysql_error());

    print (
    "Thanks for registering with [url]www.z.com[/url] <?php echo $firstname; ?> , we have sent you a email with instructions 
              on how to activate your account."
    );

    }

    ?>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    I don't understand what you want to do. Check the user has entered a first name in the forma that submitted the user name and password?

    If the code above doesn't work, it is becuase it has errors in the last print statment. You need to escape double quotes with backslashes.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139
    Originally posted by visualAd
    I don't understand what you want to do. Check the user has entered a first name in the forma that submitted the user name and password?

    If the code above doesn't work, it is becuase it has errors in the last print statment. You need to escape double quotes with backslashes.
    Sorry, the above works well but the user right now can leave out a field such as... let's say firstname.. now if I want to add a line in there to stop them maybe a if $firstname == "" then something..... but not to sure how to add it to this code

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Yeah that is what you do. If a user enters nothing, then the string will be blank, so a check like this will suffice:
    PHP Code:
    if ($firstname == '') {
        die (
    'You must enter a First Name');

    You can also do a simple client side check too, using javascript.


    P.s: If I were you I would turn off register globls and use addslashes() to escape variables, bcause your script is vunerable to SQL injections, whereby a user could gain access your system.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Also, if you're not going to turn of register_globals, decide on whether you want to use $regular globals or superglobals ($_POST['superglobals']), because using both just makes your code look silly.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width