SitePoint Sponsor

User Tag List

Page 1 of 6 12345 ... LastLast
Results 1 to 25 of 150

Hybrid View

  1. #1
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Am I doing something wrong here..?

    Hi

    Okay, so I'm following some tutorials and trying to make a rudimentary dating site using PHP and MySQL to get the hang of this stuff.

    STAGE ONE

    So I kinda thought it out on paper and came up with the following database structure:
    PHP Code:
    Members(memberIDmFornamemSNamemEmailmGendermDOBmHasChildrenmSmokesmDrinksmAboutYourselfmAboutFamilymJoinDatemUsernamemPassword
     
    Lookup(relMemberIDrelReligionIDrelRelationIDrelMStatusIDrelHeightIDrelBuildIDrelComplexionIDrelCBirthIDrelCOriginIDrelEducationIDrelOccupationIDrelDietID
     
    Religion(religionIDreligionName
     
    Country(countryIDcountryName
     
    Occupation(occupationIDoccupationName
     
    Height(heightIDheightValue
     
    Build(buildIDbuildType
     
    Age(ageIDageValue
     
    MStatus(mMStatusIDmMStatusType
     
    Education(educationIDeducationType
     
    Relation(relationIDrelationType
     
    Complexion(complexionIDcomplexionType
     
    Diet(dietIDdietType
    Okay, so that covers the database.. I then created that and have that all set-up and ready.

    STAGE TWO

    Now, I'd thought I'd give it a go at writing a joining script.

    Firstly, I read somwhere that it was a good idea to seperate the database connection stuff, so I do that and 'import' the configuration file 'conf.php' and then I do the database connection stuff:
    PHP Code:
    <?php if (isset($_POST['submit'])) {    // a new member joins using the form below 
        
    include("conf.php" );        // include the configuration file 
     
        // open database connection 
        
    $connection mysql_connect($host$user$pass) or die ("Unable to connect to database!" ); 
     
        
    // select database 
        
    mysql_select_db($db) or die ("Unable to select database!" );
    Then I thought I should create a record, so I did this as follows:
    PHP Code:
    // generate and execute query 
        
    $query "INSERT INTO Members SET " 
             
    "mForename    =    $_POST['Forename'], " .        // forename 
             
    "mSName    =    $_POST['Surname'], " .        // surname 
             
    "mEmail    =    $_POST['EMail'], " .        // e-mail 
             
    "mGender    =    $_POST['gender'], " .        // gender 
             
    "mDOB        =    $_POST['mDOB'], ".        // date of birth 
             
    "mHasChildren    =    $_POST['haschildren'], " .    // do they have children? 
             
    "mSmokes    =    $_POST['smoking'], " .        // do u smoke? 
             
    "mDrinks    =    $_POST['drinking'], " .        // do u drink? 
             
    "mAboutYourself=    $_POST['aboutyourself'], " .    // more about yourself 
             
    "mAboutFamily    =    $_POST['aboutfamily'], " .    // more about your family 
             
    "mJoinDate    =    $_POST['DATE'], " .        // date of registration 
             
    "mHeardFrom    =    $_POST['Heardfrom'], " .    // how did u hear about us? 
             
    "mUsername    =    $_POST['Username'], " .        // selected USERNAME 
             
    "mPassword    =    $_POST['encrypted_password']";    // selected PASSWORD 
     
        
    $result mysql_query($query) or die ("Error in query: $query. " mysql_error()); 
     
        
    $memberID mysql_insert_id(); 
     
        
    // generate and execute query 2 
        
    $query2 "INSERT INTO Lookup SET " 
             
    "relMemberID     =    '$memberID', " .    // member ID 
             
    "relReligionID =    'religion', " .     // religion (hidden field) 
             
    "relRelationID =    'relation_id', ".     // relationship of person posting profile to member 
             
    "relMStatus     =    '$mstatus_id', " .    // marital status 
             
    "relHeightID     =    '$height_id', " .    // height 
             
    "relBuildID     =    '$build_id', " .    // build 
             
    "relComplexionID=    '$complexion_id', " .    // complexion 
             
    "relCBirthID     =    '$country_id1', " // country of origin 
             
    "relCOriginID     =    '$country_id2', " .     // country of birth 
             
    "relEducationID =    '$education_id', " .    // education 
             
    "relOccupationID=    '$occupation_id', " .    // occupation 
             
    "relDietID     =    '$diet'"; .        // diet 
    $result2 mysql_query($query2) or die ("Error in query 2: $query2. " mysql_error()); 
    Then, I thought I'd pre-set all my SQL for the drop-down boxers etc:
    PHP Code:
    } else { 
     
        
    // 1. relation query ///// 
        
    $relation_query mysql_query("SELECT relationID, relationType FROM Relation" ); 
     
        
    // 2. marital status query ///// 
        
    $mstatus_query mysql_query("SELECT mstatusID, statusType FROM MStatus" ); 
     
        
    // 3. height query ///// 
        
    $height_query mysql_query("SELECT heightID, heightCM, heightValue FROM Height ORDER BY heightCM" ); 
     
        
    // 4. build query ///// 
        
    $build_query mysql_query("SELECT buildID, buildType FROM Build" ); 
     
        
    // 5. complexion query ///// 
        
    $complexion_query mysql_query("SELECT complexionID, complexionType FROM Complexion" ); 
     
        
    // 6. country query ///// 
        
    $country_query mysql_query("SELECT countryID, countryName FROM Country" ); 
     
        
    // 7. education query ///// 
        
    $education_query mysql_query("SELECT educationID, educationType FROM Education" ); 
     
        
    // 8. occupation query ///// 
        
    $occupation_query mysql_query("SELECT occupationID, occupationName FROM Occupation" ); 
    ?> 
    Finally, write a simple form to fill in:
    PHP Code:
    <FORM ACTION="<?php echo($_SERVER['PHP_SELF']); ?>" METHOD="POST"> 
    <DIV ALIGN="CENTER"> 
         <TABLE CELLSPACING="2" CELLPADDING="2" BORDER="0" WIDTH="98%"> 
     
    ... various fields... 
     
    <TR VALIGN="middle"> 
    <TD>Profile created by:</TD> 
    <TD> <SELECT NAME="relation_select" alt="select" /> 
    <OPTION SELECTED VALUE="">-----------</OPTION> 
    <?php 
        
    while ($rel_q mysql_fetch_array($relation_query)) { 
            
    $relation_id $rel_q["relationID"]; 
            
    $relation_title $rel_q["relationType"]; 
            echo(
    "<OPTION VALUE='$relation_id'>$relation_type<BR>\n" ); 
                } 
             
    ?> 
    </SELECT> </TD> 
     
    ...etc.. for the other queries..
    STAGE THREE

    Okay, so I load it up in the browser, and it all displays.. way hey! But then I look at some of the fields that should contain information from the database but there is nothing in there???

    Am I doing something wrong with the mysql_fetch_array???
    Does the the rest of it look okay or am I doing something wrong???

    So.. can anyone helps please?

    Thanks.

    Mak

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It all looks pretty good. I did spot one mistake:
    Code:
    <FORM ACTION="<?php echo($_SERVER['PHP_SELF']); " METHOD="POST">
    You're missing a closing ?> tag here.
    Code:
    <FORM ACTION="<?php echo($_SERVER['PHP_SELF']); ?>" METHOD="POST">
    Otherwise it looks good. Perform a View Source in your browser and check for PHP error messages in the source code that may not be showing up on the page.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for the reply Kevin!

    Okay, I corrected the error you mentioned. Secondly, I had a look using the view source and found that at the following point of code:

    <TD>Profile created by/TD>
    <
    TD> <SELECT NAME="relation_select" alt="select"
    />
    <
    OPTION SELECTED VALUE="">-----------</OPTION
    >
    <?
    php
    while ($rel_q = mysql_fetch_array($relation_query
    )) {
    $relation_id = $rel_q["relationID"
    ];
    $relation_title = $rel_q["relationType"
    ];
    echo(
    "<OPTION VALUE='$relation_id'>$relation_type<BR>\n"
    );
    }
    ?>
    </SELECT> </TD>


    I get the following error:
    PHP Code:
    <TR VALIGN="middle"
                 <
    TD>Profile created by:</TD>
                 <
    TD> <SELECT NAME="relation_select" alt="select" />
                     <
    OPTION SELECTED VALUE="">-----------</OPTION>
                     <
    br />
    <
    b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>d:\join5.php</bon line <b>140</b><br />
                    </
    SELECT> </TD>
                 <
    TD BGCOLOR="#EEEEEE">Relationship with the person whos profile is being posted</TD>
                </
    TR
    Any ideas as to what is happening here?

    Thanks.

    Mak

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's probably something wrong with your query. Try adding 'or die(mysql_error());' at the end pf all the queries you're executing.
    PHP Code:
    $relation_query mysql_query("SELECT relationID, relationType FROM Relation") or die(mysql_error()); 
    Hope this helps.

    -Helge

  5. #5
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Excellent! That worked!

    Okay, now it says:

    No Database Selected

    Hmm, but I have the following configuration file:

    PHP Code:
    <?
    // conf.php - configuration parameters
    // database configuration
    $host "localhost";
    $user "root";
    $pass "gc-161";
    $db "pa";
    ?>
    Is that not sufficient? Do I need:
    PHP Code:
    mysql_select_db("pa"); 
    in every .php file?!

    Thanks.

    Mak

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You are selecting the database in the 'if' branch of your if-else statement, but not in the 'else' branch.

    Your best bet is probably to stick the database connection and selection code into the conf.php file where all pages can use it.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  7. #7
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Mak,

    This is what I use for my username and passwords..

    Your username must be a minimum of 5 characters and a maximum of 10 characters in length, contain alphanumeric characters only and the first character must be alpha.

    Your password must be a minimum of 5 characters and a maximum of 10 characters in length, contain alphanumeric characters only, the first character must be alpha and must contain at least 1 numeric character.

    And then the php code I use to work it out...
    Code:
    if (empty($formVars["user_ca"])) {
    $errors["user_ca"] = "Please enter a username.";
    } 
    elseif (strlen($formVars["user_ca"]) < 5) {
    $errors["user_ca"] = "Username must be greater than 5 characters in length."; 
    } 
    elseif (strlen($formVars["user_ca"]) > 10) {
    $errors["user_ca"] = "Username must be less than 10 characters in length."; 
    } 
    elseif (!ereg("^[a-zA-Z0-9]+$",$formVars["user_ca"])) {
    $errors["user_ca"] = "Username must be alphanumeric only."; 
    } 
    elseif (!ereg("^[a-zA-z]+",$formVars["user_ca"])) {
    $errors["user_ca"] = "Username does not start with an alpha character"; 
    } 
    elseif (mysql_num_rows($sql_user)) {
    $errors["user_ca"] ="That username already exists, please try another one.";
    }
    // validate the password field
    if (empty($formVars["pass1_ca"]) or empty($formVars["pass2_ca"])) {
    $errors["pass1_ca"] = "Please complete both password fields.";
    } 
    elseif ($formVars["pass1_ca"] != $formVars["pass2_ca"]) {
    $errors["pass1_ca"] = "The password fields do not match, please try again.";
    } 
    elseif (strlen($formVars["pass1_ca"]) < 5) {
    $errors["pass1_ca"] = "Password must be greater than 5 characters in length."; 
    } 
    elseif (strlen($formVars["pass1_ca"]) > 10) {
    $errors["pass1_ca"] = "Password must be less than 10 characters in length."; 
    } 
    elseif (!ereg("^[a-zA-Z0-9]+$",$formVars["pass1_ca"])) {
    $errors["pass1_ca"] = "Password must be alphanumeric only."; 
    } 
    elseif (!ereg("[0-9]",$formVars["pass1_ca"])) {
    $errors["pass1_ca"] = "Password does not contain a numeric"; 
    } 
    elseif (!ereg("^[a-zA-z]+",$formVars["pass1_ca"])) {
    $errors["pass1_ca"] = "Password does not start with an alpha character"; 
    }
    so I have 2 password fields to make sure that they type it in correctly, I also check the username hasn't already been used previously by reading the database.

    You should be able to change the alpha numeric line to include the '-' character and ignore the it must start with a letter section.

    (by the way if you want this as javascript (server side) then please create a new thread in the javascipt section not the PHP section)

    Sarah
    Last edited by Sarah; Apr 7, 2003 at 08:13.
    Regular user

  8. #8
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Okay, thanks Sarah.

    Just a quick question or two, however:

    The reason I am considering client-side validation is that, as you all know, the form does not need to be submitted for validation and checking to take place. Thus, saving processing at the server-side and also time.

    Is that a plausible enough reason to go with the client-side approach rather than embedded validation code within PHP (i.e. server-side).

    Would there be any drastic reasons to go with the server-side approach?

    Thanks.

    Mak

  9. #9
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Mak,

    Basically if a user turns off javascript then no checking is done on your form - and that can leads to huge problem!

    What I tend to do now is only PHP server side validation, and if I can throw in some client side on top BUT as long as the PHP does everything and more the JS code does.

    So yes you should do the server side approach regardless the question is whether to bother doing client side as well.

    Sarah
    Regular user

  10. #10
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sarah

    Just a quick query..

    In your example, what is '$formVars'? Is it the name of the form? (my form does not have a name) and 'user_ca' is that the username field, hence 'Username' in my script?

    Thanks.

    Mak

  11. #11
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Does that sound right?

  12. #12
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Following Sarah's point on client/server-side I'd agree that you should use only server-side for FORM validation.

    It is a -BEEP- nightmare correcting data that isn't validated due to someone having Javascript disabled.

    You normally would give a FORM a name though for the point to check if a FORM has been posted or not you only need to give a name to the SUBMIT input element.

    PHP Code:
    <form name='OneDay' method='post' action='index.php'>
    .
    .
    .
    <
    input type='submit' name='Submission' value='Log On'>
    </
    form
    And then in your script to see if this FORM has been sent or not use:

    PHP Code:
    if(!isset($_POST['Submission'])) {
    # not sent yet so re-display FORM again

    else {
    # I have sent the FORM so validate it

    Happy Trails....

  13. #13
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi

    Okay, I have named my form 'mainform' and to test I have entered the following code:
    PHP Code:
    if (empty($mainform["Forename"])) {
       
    $errors["Forename"] = "Please enter your forename.";
     } 
    Above this part in the script (refer to earlier posts for code):
    PHP Code:
    // generate and execute query
     
    $query "INSERT INTO Members SET " .
    .
    .

    However, it still does not seem to work. What am I doing wrong?

    Thanks.

    Mak

  14. #14
    SitePoint Addict sojomy's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Following Sarah's point on client/server-side I'd agree that you should use only server-side for FORM validation.
    While I agree that the serverside check is a MUST, if you run a busy website, it would be well worth the extra 15 minutes it takes to add a little javascript checking too. The javascript should add less than 1K to your files, but can save your users from reloading a 10K, 30K or even larger file if the whole form has to be redisplayed with error messages. It saves the end-user time by seeing the error message instantly rather than waiting for the page to be reloaded. And if they have javascript turned off, oh well, you still have the PHP error messages to fall back on. But it saves server resourses if you don't have to reload the page over and over, especially if you only show the first error message that PHP comes across and then redisplay the form. And every little resource saved it worth it

    Just my opinion

  15. #15
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Help people?!

    I'm still stick!

  16. #16
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    or stuck I think you mean

    Anyway try something like this

    Code:
    if (empty($_POST["Forename"])) {
     echo"Please enter a username.";
    } 
    Then you should put all the validation stuff in an if else loop so that if it fails for whatever reason it won't try to input anything into the dB

    Sarah
    Last edited by Kevin Yank; Apr 7, 2003 at 18:56.
    Regular user

  17. #17
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Stuck, yes, LOL

    Okay, I tried what you suggested Sarah, but it still does not work.

    Basically, what I have is as follows:

    PHP Code:
    <?php if (isset($_POST['submit'])) { // a new member joins using the form below
     
    if (empty($_POST["Forename"])) {
       echo 
    "Please enter your Forename.";
     } 
     
     
    // generate and execute query
        
    .... etc
     
     $result 
    mysql_query($query) or die ("Error in query: $query. " mysql_error());
     
    $memberID mysql_insert_id();
     
     
    // generate and execute query 2
        
    ... etc
     
    $result2 
    mysql_query($query2) or die ("Error in query 2: $query2. " mysql_error());
    } else {
     
    // all the queries for the drop-down boxes, etc.
     
    ?>
     
     <FORM NAME="mainform" ACTION="<?php echo($_SERVER['PHP_SELF']); ?>" METHOD="POST" onSubmit="return validateForm(this);" onFocusOut="clearStyle(event.srcElement);">
       <DIV ALIGN="CENTER"> 
           <TABLE CELLSPACING="2" CELLPADDING="2" BORDER="0" WIDTH="98%">
               <TR VALIGN="middle"> 
                  <TD colspan=2 CLASS="smalltextbold"><p>PM Registration</p>
                    <p>Please fill in all fields:<br>
                    </p></TD>
                  <TD>&nbsp;</TD>
                </TR>
                <TR VALIGN="middle"> 
                  <TD>&nbsp;</TD>
                  <TD>&nbsp;</TD>
                  <TD BGCOLOR="#EEEEEE">&nbsp;</TD>
                </TR>
                <TR VALIGN="middle"> 
                  <TD>Forename:</TD>
                  <TD><INPUT TYPE="text" class="forminput" NAME="Forename" maxlength="20" ></TD>
                  <TD BGCOLOR="#EEEEEE">Please enter your first name</TD>
                </TR>
     
    ... etc ...
    The above is the top part of the form (note that the 'onSubmit' part is for a Javascript validation file.. just ignore it, LOL ).

    So that's what I have.. and to me, it seems all okay.. so I am not sure why the little tester validation bit doesn't work?!

    Any ideas?

    Thanks.

    Mak

  18. #18
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Mak,

    I would put the Forename section also into a if|else statement like this:
    PHP Code:
    <?php if (isset($_POST['submit'])) { // a new member joins using the form below
      
    if (empty($_POST["Forename"])) {
        echo 
    "Please enter your Forename.";
      } else {

    // generate and execute query
    .... etc

      $result 
    mysql_query($query) or die ("Error in query: $query. " mysql_error());
      
    $memberID mysql_insert_id();

    // generate and execute query 2
    ... etc

      $result2 
    mysql_query($query2) or die ("Error in query 2: $query2. " mysql_error());
      }
    } else {
    That way it should stop at the echo "Please enter your Forename" and not continue if that condition is true...

    So you say it didn't work - what is it doing instead? Can you check that Forename matches what you are using in your form...

    Anyway see what that does.. if not you could try
    PHP Code:
     $_POST['Forename'] == "" 
    instead of empty?

    Sarah
    Regular user

  19. #19
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Still does not work..!

    Hi

    Well, when it didn't work, it just by-passed the validation code for the 'Forename' field completely. i.e. did not check it, but the script displayed.

    As is shown in the form code, the name of the field does correspond (it is 'Forename'). Hence, it can't be that?

    I have also tried both methods of what you just suggested and when I include an 'else' it says:

    Parse error: parse error, unexpected T_ELSE in d:\join6.php on line 70


    Then I tried both methods without the else, but once again, as previously, it just bypasses the validation code and runs the script as if the code was not there.

    I'm confused

    Help!!

    Mak

  20. #20
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    when you got the error it means that it started working which is line 70? and also post the whole page here (minus the chunk of form code like before) but I am interested in the end of the script too, ie making sure the else statement is ended correctly

    Sarah
    Regular user

  21. #21
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Okay, line 70 is the '} else {' of the Forename check below (before that is just some HTML code.

    Here is how the script goes:

    PHP Code:
    <?php
     
    include("conf.php");  // include the configuration file
    ?>
    <?php 
    if (isset($_POST['submit'])) { // a new member joins using the form below
     
    if ($_POST["Forename"]='') {
          echo 
    "Please enter your Forename.";
       } else {
     
     
    // generate and execute query
     
    $result mysql_query($query) or die ("Error in query: $query. " mysql_error());
     
    $memberID mysql_insert_id();
     
     
    // generate and execute query 2
     
    } else {
     
    // queries for drop-down boxes
     
    ?>
    Then comes the form (top part posted earlier).

    That's about it..

    Any ideas?

    Thanks.

    Mak

  22. #22
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you have missed off your ending } see below
    PHP Code:
    <?php
    include("conf.php" ); // include the configuration file
    ?>
    <?php 
    // start first if else statement
    if (isset($_POST["submit"])) { // a new member joins using the form below
    //start second if else statement
      
    if (empty($_POST["Forename"])) {
        echo 
    "Please enter your Forename.";
      } else {
    // generate and execute query
    $result mysql_query($query) or die ("Error in query: $query. " mysql_error());
    $memberID mysql_insert_id();
    // generate and execute query 2
      
    // end second if else statement
    } else {
    // insert form here
    // end first if else statement
    ?>
    I have added the last } bracket also as you didn't post the whole code so I didn't know if you did that end close bracket part... but have tested this on my system and it works - if this doesn't then check the submit button values for name to make sure they match the isset section

    Sarah
    Regular user

  23. #23
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Okay, remember after:

    PHP Code:
    // generate and execute query 2 
    I have:
    PHP Code:
    $result2 mysql_query($query2) or die ("Error in query 2: $query2. " mysql_error()); 
    So does the closing curly brace for the second end if-else statement go before the $result2 above or after?

    THEN, after $result2 I have:

    PHP Code:
    } else { 
    Then come the drop-down box queries, NOT the form. So after those I should end first if-else statement thus:

    PHP Code:
    }
    ?> 
    Is that right?

    Thanks.

    Mak

  24. #24
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ok I don't understand why you have that if else query before the drop down boxes (which I took to be the form...) move that else to after the drop down boxes and move the second end if else } to after the drop down boxes, then process the form then have a last }.

    As before if you can post your code taking out long section of code BUT leaving in the if else structure then I can help a bit more.

    But essentially the if else statement for the Forename section should only end after you have done ALL updating to the dB and drop down boxes etc etc . next will come the form which is in the first if else statement.

    Basically you didn't have enough if else statement and brackets hence the error, try and indent each if else section that way you can see what goes in where

    Sarah
    Regular user

  25. #25
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Confused

    Hi

    Sorry, getting a bit confused now

    The structure I am using is:

    PHP Code:
    if (isset($submit)) {
      
    //  form has been submitted -> do form validation fields.
      // connecto to DB and insert new record
     
    } else {
      
    // connect to DB
      // pre-set SQL for drop-down boxes
      // write out FORM for user to fill in
     

    Hence, I constructed:
    PHP Code:
    <?php if (isset($_POST['submit'])) { // a new member joins using the form below  
    // generate and execute query
     
    $query "INSERT INTO Members SET " .
     ... 
    etc
     
    $result 
    mysql_query($query) or die ("Error in query: $query. " mysql_error());
     
    $memberID mysql_insert_id();
     
    // generate and execute query 2
     
    $query2 "INSERT INTO Lookup SET " .
     ... 
    etc
     
    $result2 
    mysql_query($query2) or die ("Error in query 2: $query2. " mysql_error());
    } else { 
     
      
    // drop-down box query code
     

    ?>
     
    <FORM NAME="mainform" ACTION="<?php echo($_SERVER['PHP_SELF']); ?>" METHOD="POST"
     
    ... etc (form follows)
    Right, so where in that did you suggest I should put:
    PHP Code:
    if ($_POST["Forename"]='') {
         echo 
    "Please enter your Forename.";
     } else { 
    Okay, sorry for my confusion but it would be a lot easier to point out my errors in the code I have posted as a whole.

    Thanks.

    Mak


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
  •