SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all!

    I have devised a script which submits information into my database (via a user form), it's currently working fine.

    However I have tried to fit in some code which will check to see whether the value within the feild 'user_name' already exists within the database, if it does, then the user is asked to choose another user_name! I have made user_name a unique feild. Therefore the script MUST contain clause which prevents users from entering the same user_name.

    Sounds simple enough, yet there is a problem with the script.

    Everytime I run the script, the following error message appears:

    Parse error: parse error, expecting `'('' in /usr/home/sites/Koncise/web/Submit_love.php on line 8

    Here is my script:

    <?php


    mysql_connect("localhost","*****","****");
    mysql_select_db("******");
    $result = mysql_query ("SELECT user_name from ****** where user_name='$user_name'");
    if mysql_num_rows($result) == 1 { echo ("Sorry your chosen username has been selected by another user, please choose another one!"); }


    if ($submit == "submit") {

    if ($user_name=="" or $password=="" or $group_name=="" or $contact_name==""
    or $address=="" or $city=="" or $email=="" or $post_Code=="") {
    echo("One or more required fields were left blank. Please fill them in and try again.");

    } else {

    mysql_connect("local","*****","******");
    mysql_select_db("****");
    mysql_query("INSERT INTO ***** SET
    ID='$ID', user_name='$user_name', password='$password',
    category='$category', group_name='$group_name', contact_name='$contact_name',
    region='$region', address='$address', post_Code='$post_Code', city='$city',
    telephone='$telephone', fax='$fax', homepage='$homepage', email='$email',
    group_Information='$group_Information', practice_days='$practice_days',
    conditions_of_joining='$conditions_of_joining'");

    echo("Thanx for your submission!");
    }

    } else {
    echo("No Action Specified.");
    }
    ?>



    The error points to where the user_name check appears on line 8. Please, please could somebody point out what is wrong with it!!

    Many many thanx!


    Koncise.

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if mysql_num_rows($result) == 1 { echo ("Sorry your chosen username has been selected by another user, please choose another one!"); }

    Should be:

    if (mysql_num_rows($result) == 1) { echo ("Sorry your chosen username has been selected by another user, please choose another one!"); }

    The if statment need a () around the condition
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much Son Nguyen, however after running the script, it still submits the information....even when a the value within the 'user_name' feild already exists in the database
    and the following user_name check code is totally ignored!!!

    Here is the user_name check code once again:

    mysql_connect("localhost","Koncise","castor");
    mysql_select_db("Koncise");
    $result = mysql_query ("SELECT user_name from Groups where user_name='$user_name'");
    if (mysql_num_rows($result) == 1) { echo ("Sorry your chosen username has been selected by another user, please choose another one!"); }


    Thanx again!!!

    Koncise

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much Son Nguyen, however after running the script, it still submits the information....even when a the value within the 'user_name' feild already exists in the database
    and the following user_name check code is totally ignored!!!

    Here is the user_name check code once again:

    mysql_connect("localhost","****","*****");
    mysql_select_db("*****");
    $result = mysql_query ("SELECT user_name from ***** where user_name='$user_name'");
    if (mysql_num_rows($result) == 1) { echo ("Sorry your chosen username has been selected by another user, please choose another one!"); }


    Thanx again!!!

    Koncise


    (please accept my apologies if this relpy was posted twice)

  5. #5
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Koncise
    Thank you very much Son Nguyen, however after running the script, it still submits the information....even when a the value within the 'user_name' feild already exists in the database
    and the following user_name check code is totally ignored!!!

    Here is the user_name check code once again:

    mysql_connect("localhost","****","*****");
    mysql_select_db("*****");
    $result = mysql_query ("SELECT user_name from ***** where user_name='$user_name'");
    if (mysql_num_rows($result) == 1) { echo ("Sorry your chosen username has been selected by another user, please choose another one!"); }

    Thanx again!!!

    Koncise
    You need something to stop execution of the script because it continues on at that point. Try:

    PHP Code:
    if( mysql_num_rows$result ) == ) { 
      echo (
    "Sorry your chosen username has been selected by another user, please choose another one!"); 
      exit;


  6. #6
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, Matt showed you
    Don't worry of posting twice, I've been thanked twice
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  7. #7
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you do this :


    first you put a hidden input field in your form and name it something like " bla " with a value of " alb ".

    then follow this example for the script.

    Code:
    <?
    
    //START ERROR MESSAGE
    $errorMsg = "<TABLE BORDER=0 cellpadding=\"0\" cellspacing=\"0\"><TR><TD width=\"250\"></TD><TD>\n";
    $errorMsg .= "<FONT class=\"textred\">Your submission was not processed because of the following errors :\n<UL>";
    $errorMsgEnd = "</UL>\nPlease enter the required information and resubmit.</FONT>\n";
    $errorMsgEnd .= "</TD></TR></TABLE>\n";
    //End Error Message
    
    $formblock = "put your form in here. you'll need to escape quotes and stuff"
    
    //then you can do your if statements like this
    
    if ($bla == "alb") {
    $send = "yes";
    }
    
    else {
    $send = "no";
    }
    
    if (bla bla bla == $this){
        
        $FirstError = "<LI>username is taken</LI>\n";
        $send = "no";
    }
    
    // and so for all your form fields
    //then you can say
    
    
    if ($send == "no") {
    
    echo "$errorMsg";
    
    echo "$FirstError";
    
    echo "$errorMsgEnd";
    
    echo "$formblock";
    }
    
    // then if send == yes
    
    if ($send == "yes") {
    
    mysql_query("INSERT INTO ***** SET 
    ID='$ID', user_name='$user_name', password='$password', 
    category='$category', group_name='$group_name', contact_name='$contact_name', 
    region='$region', address='$address', post_Code='$post_Code', city='$city', 
    telephone='$telephone', fax='$fax', homepage='$homepage', email='$email', 
    group_Information='$group_Information', practice_days='$practice_days', 
    conditions_of_joining='$conditions_of_joining'"); 
    
    }
    
    echo("Thanx for your submission!");
    this is basically the way i have it set up for my site but with about 30 form fields.

    i hope you can make sense of what i just wrote. it makes sense to me but then again i've been up for 20 hrs now.

    the way it works is that if there is an error, the script will display the error message depending on what field had the error and also display the form again.

    if you have questions let me know.
    . . . chris

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx very much guys, the code works fine now..great!!!

    Koncise.

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really do appriciate the help guys...

    However I also wanted a 'confirmation e-mail' sent to each user who succseesfully submits information to the database.
    Which would say something like,

    "Thank you $user_name, your information was successfully inserted to the database...your password is $password, blah blah blah..".

    I know this would require an if statement of some kind, however I am not sure how to implement this. Is this a simple operation? Please could anyone give me an example of how to do this!!!

    Much Thanx 1nce again,

    Koncise.



    P.S. atomicmunky thanx for the help, but I think I'll stick to my original code - my time is running out!!!

  10. #10
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, no problem.
    try this for emailing the user:

    Code:
    /////////////////////////////////
    //EMAIL THE USER THEIR USERNAME & PASSWORD
    /////////////////////////////////
        $from = "YOUR COMPANY";
        $fromemail = "you@company.com";
        $headers = "From : \"$from\" <$fromemail>\n";
        $sendto = "$Email";
        $subject = "Yous Username and Password";
        $message = "Thank you for registering with YOUR COMPANY NAME\n";
        $message .= "below are you user name and password, please write them down\n";
        $message .= "for future reference. \n\n";
        $message .= "Your Username is : $uname\n\n";
        $message .= "Your Password is : $upass\n\n";
        $message .= "Thanks Again\n";
    
    
        mail($sendto, $subject, $message, $headers);
    //////////////////////////////////////////////////
    //END OF EMAIL
    /////////////////////////////////////////////////
    you probably want to put this after your INSERT statement or thank you message so that it gets executed as part of the if statement already there.
    . . . chris

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx very much atomicmunky,

    I fitted the script after the SELECT statement, however it refuses does not send the mail the user.

    Here is the script:

    <?php

    mysql_connect("****","****","****");
    mysql_select_db("*****");
    $result = mysql_query ("SELECT user_name from Groups where user_name='$user_name'");
    if( mysql_num_rows( $result ) == 1 ) {
    echo ("Sorry your chosen username has been selected by another user, please choose another one!");
    exit;
    }



    if ($submit == "submit") {

    if ($user_name=="" or $password=="" or $group_name=="" or $contact_name==""
    or $address=="" or $city=="" or $email=="" or $post_Code=="") {
    echo("One or more required fields were left blank. Please fill them in and try again.");

    } else {

    mysql_connect("****","*****","******");
    mysql_select_db("******");
    mysql_query("INSERT INTO Groups SET
    ID='$ID', user_name='$user_name', password='$password',
    category='$category', group_name='$group_name', contact_name='$contact_name',
    region='$region', address='$address', post_Code='$post_Code', city='$city',
    telephone='$telephone', fax='$fax', homepage='$homepage', email='$email',
    group_Information='$group_Information', practice_days='$practice_days',
    conditions_of_joining='$conditions_of_joining'");



    $fromemail = "Koncise20@hotmail.com";
    $headers = "From : <$fromemail>\n";
    $sendto = "$email";
    $subject = "Love2Sing registration";
    $message = "Thank you for registering with Love2Sing.co.uk\n";
    $message .= "below are you user name and password, please write them down\n";
    $message .= "for future reference. \n\n";
    $message .= "Your Username is : $user_name\n\n";
    $message .= "Your Password is : $password\n\n";
    $message .= "Thanks Again\n";


    mail($sendto, $subject, $message, $headers);



    echo("Thanx for your submission!");
    }

    } else {
    echo("No Action Specified.");
    }
    ?>


    Perhaps I have fitted it the code in the wrong place, is there something I have done wrong?

    Thanx again,

    Koncise.


    (Note I deliberately ommitted the $from variable!)

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just an added observation, Koncise, you do not need to run mysql_connect everytime you run a query just run it once at the beginning of the script and assign it to a var like
    PHP Code:
    $link_id mysql_connect("localhost"""""); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx freddydoesphp.

    However does this have any bearing as to why my confirmation email refuses to work?

    Is there a problem with my script?

    Thanx!

    Koncise.

  14. #14
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $headers = "From : <$fromemail>\n";

    (Note I deliberately ommitted the $from variable!)

    did you try putting the $from variable back in?

    other than that, i don't know why it's not working. is the data being inserted into the db properly or at all?
    . . . chris

  15. #15
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx atomicmunky,

    The information does get inserted into the database, I have checked. However the email does not work, I'll put the $from variable back in and try it again.

    Thanx,

    Koncise!

  16. #16
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again.

    Ok, there is defiantly a problem with the confirmation mail code, because everything was fine until I put it in.

    The error message which appears points towards the confirmation code. Here is the script (with the $from variable):


    <?php

    /* This script will display a html form that allows new groups to be inserted into the 'Groups' table, which exists within the database 'Love_to_sing'. */

    mysql_connect( "****", "****", "***");
    mysql_select_db("koncise_Love_to_sing");
    $result = mysql_query ("SELECT user_name from Groups where user_name='$user_name'");
    if( mysql_num_rows( $result ) == 1 ) {
    echo ("Sorry your chosen username has been selected by another user, please choose another one!");
    exit;
    }

    if ($submit == "submit") {

    if ($user_name=="" or $password=="" or $group_name=="" or $contact_name==""
    or $address=="" or $city=="" or $email=="" or $category=="Choose a category") {
    echo("One or more required fields were left blank. Please fill them in and try again.");

    } else {

    mysql_connect("***","****","*****");
    mysql_select_db("koncise_Love_to_sing");
    mysql_query("INSERT INTO Groups SET
    ID='$ID', user_name='$user_name', password='$password',
    category='$category', group_name='$group_name', contact_name='$contact_name',
    region='$region', address='$address', post_Code='$post_Code', city='$city',
    telephone='$telephone', fax='$fax', homepage='$homepage', email='$email', group_Information='$group_Information', practice_days='$practice_days',
    conditions_of_joining='$conditions_of_joining'");


    $from = "Love2Sing";
    $fromemail = "Koncise20@hotmail.com";
    $headers = "From : "$from" <$fromemail>\n";
    $sendto = "$Email";
    $subject = "Yous Username and Password";
    $message = "Thank you for registering with Love2Sing\n";
    $message .= "below are you user name and password, please write them down\n";
    $message .= "for future reference. \n\n";
    $message .= "Your Username is : $user_name\n\n";
    $message .= "Your Password is : $password\n\n";
    $message .= "Thanks Again\n";

    mail($sendto, $subject, $message, $headers);


    echo("Thanx for your submission!");


    }

    } else {
    echo("No Action Specified.");
    }
    ?>

    The error message which appears says:

    "Parse error: parse error in /home/koncise/public_html/Submit_love.php on line 33."

    Which points to the part of the script which contains the confirmation email code!

    Please please can anyone point out the error!!!

    Thanx 1nce again,

    Koncise

  17. #17
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, try this.

    change this line :

    Code:
    $headers = "From : "$from" <$fromemail>\n";

    to this :

    Code:
    $headers = "From : \\\"$from\\\" <$fromemail>\n";
    see if that works, or if you get any more errors. and we'll go from there. i really can't see anything else that would not make it work.
    what about the last else statement? what's that all about? is it necessary? remove that just to check if it works w/o it.
    Last edited by atomicmunky; Mar 13, 2001 at 22:04.
    . . . chris

  18. #18
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    err...ok,

    But I fail to see a difference between the two codes!!

    Koncise!

  19. #19
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    atomicmunky is correct. You were trying to encapsulate a string with double quotes that has double quotes in it. That is why you were having the problem with that line.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  20. #20
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh yes, of course!

    My apologies guys, I have to pay more attention to detail!
    I'll make the change and try it again.

    Thank you very much.

    Koncise!

  21. #21
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again!

    Hey, it works!!!

    The email is succsessfully sent to the email address specified within the Submition form!!!

    Big, big thanx to atomicmunky, freddydoesphp, Son Nguyen and Matt R for taking the time to help me out, it has been much appreciated.

    Here is the Full code in all its glory:

    $from = "Love2Sing";
    $fromemail = "Koncise20@hotmail.com";
    $mailheaders = "From: Love2Sing.co.uk\n";
    $sendto = "$email";
    $subject = "Love2Sing - Your Username and Password";
    $message = "Thank you for registering your group with Love2Sing.co.uk.\n\n";
    $message .= "Below are your user name and password, please keep them\n";
    $message .= "for future reference. \n\n";
    $message .= "Your Username is : $user_name\n\n";
    $message .= "Your Password is : $password\n\n";
    $message .= "Please feel free to update the details of your group at any time\n";
    $message .= "by entering the 'Members Login' area and supplying your user name\n";
    $message .= "and password when prompted.\n\n";
    $message .= "Thanks Again!\n\n";
    $message .= "-------------\n";
    $message .= "Webmaster\n";

    mail($sendto, $subject, $message, $mailheaders);


    Note: I changed the $headers variable to $maiheaders with the value = "From: Love2Sing.co.uk\n";.
    This was because the mail would arrive in my inbox inicating that the sender was 'Unknown'. However now I have made the name of my site (Love2Sing.co.uk) will appear as the sender instead.


    Thanx again guys!!!


    Koncise.


Bookmarks

Posting Permissions

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