The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

like we changed the mDOB stuff to remove the POST in eth sql query you also need to do the same with the password in the sql query, because you already get the $_POST value of password and using that you create the $encrypted value so therefore the line in the sql query should just read

Yeah that worked a treat, except that I had to move the md5 part to to the top so that it does it after the form has been submitted - see, I am learning.. slowly but surely! [img]images/smilies/biggrin.gif[/img]

You see, all this other information about a individual's diet (or whatever), I do not want stored in the main Members table. As a result, I have this table which should contain relative-keys as to which member has what particulars. For example:

Member 1 has a diet of 1 (which is vegetarian) and education of 3 (which is a batchelors).. and so on. Each time when a member joins, they enter a record for the member table, and subsequently, corresponding relation-keys are entered into this table.

There may be a UNI within a related table that has a relationship with this one ?

There is definitely a database design issue there somewhere.

Looking at my table again I think - key 1 - could be something to do with your PK. This could be this table it's self or another ID within another table that is related to this tables - the one you've put up in this forum - id.

I was thinking about this earlier and another thing that might cause this problem is that your putting a different data type into a field in this table - posted earlier - that should be something else ?

For example, a string is going into one of your IDs and in fact it should be an integer.

Are your values your inserting into the table all correct ? BTW an update is only used to update a record already there so stick with the insert 8)

can you check the page source when you view the actual form itself to check that you are actually getting ID values for the martial status etc? So print out here the html source code here to show us.

then write echo "lookup... insert your full lookup query2 here" BEFORE the actual query2 line that will show whether you have a problem with the data not being passed from the form OR its the insert into the dB issue.

because you have the error saying 0-0-0-0-0- etc I would think you are somehow not getting those ID values from the form correctly... and don't worry about the duplicate error as I am pretty sure when we did your dB Schema that is correct

also you don't need to have single quote around these lookup values as they are just integers (but that shouldn't be an issue)

HMM skip the above Mak, on your form side you have shown the Marital one here and the name of that drop down box is marital? therefore your post values should be $_POST['marital'] and not $_POST['mstatusid'], as its the NAME of the form field that is passed and not the value you inserted? Does that make sense? try echoing out $_POST['marital'] just before the $query2 part and see if that gives you the value - if it does then just run through each form segment getting the form name (i.e. <select name="marital">)

Yes, you were absolutely right Sarah. [img]images/smilies/biggrin.gif[/img] [img]images/smilies/thumbs_up.gif[/img]

I was trying to post the variables themselves rather than the name of the 'select' in which they were assigned and encapsulated.

Now, apart from a few little tinkers to the various things I have been working on so far, I can register a member.

What I now need is input from you guys as to how I deal with a couple of things:

1. Currently, if there are any errors when adding user details, a blank page comes up with an echo of the error. I was thinking of ammending this so that on submission, if any errors are discovered, they are displayed on the same (original) page in say, red, allowing the user to correct them.

Is this the best way to go about it? If so, how? (NOTE: currently I am posting to PHP_SELF).

2. Is the use of sessions on such a site a necessary requirement or, in-fact, worth doing?

Ummm.... In the event that a user / script gives an error on the same page you should consider using output buffering.

To get a better idea of what this is and how it works you should read the manual 8)

But in the meantime I use this to put errors on the page regardless of when an error occured within the script - i.e. an error could occur near the end and still the error will display okay - w/out prior HTML output 8)

Start at very top of page BEFORE any output at all - as in the case of using COOKIEs - to use output buffering:

PHP Code:

<?php# start buffering hereob_start();# following gets printedecho('Hello World !!');..# some more script which generates an error# now I give an errorob_clean();ReportError('Bad User Inputs');?>

Now this function 'ReportError' will format and display the error in it's own way - ie not using the page layout dependent on your scripts generated output.

So for example I could put the error in it's own table - in this example I call a function though but normally I would INCLUDE a page to be displayed passing it the error message. 8) Any content generated by your script will not be displayed either once you've used ob_clean().

I'm sorry if I am being thick here (and no funny comments if I am!!), but is there no way of going about it without going through the classes rigmarol?

[It's just that I am sure that, in-passing, I have seen people do what I require in a relatively easy way. Eg. the user presses submit, if there is an error in regards to validation, they are taken to the top of the page and in red-colour, told to correct the error (maybe with a asterisk next to the field(s))].

yeah Mak there is, I will need to respond when in work as most of the code that I work on is there, but basically you will need to set an error array at the start of the code and then fill it with any error message as you go along, which on submits displays them next to the form sections.

BUT it can be quite complicated so not trying to put you off or anything I woudl get teh rest working and leave it that it goes to a new page listing all the error messages (which you can alter to say Name or which field you are talking about) and then say click back to make changes. Otherwise you will need to change the way you have done the validation etc etc personally I have used this method once and still prefer doing the old fashioned version - makes life much easier...

I think though you could probably do something half way in between (just thinking off top of head now) but instead of showing a new page you could echo out the errors just at the top of the page allowing them to make the changes directly, getting * next to the form in question is a little harder though.

Basically with the code that you have you know you have print form, press submit, do error checking, update dB. well after error checking you display form again if any errors were found, so you would need to include the whole form again, but instead of having all the areas blank you would use the $_POST['marital'] as the value of the form boxes so they would already be filled in.

Hopefully that makes some sense, short on time tonight - let me know whether you get my drift and I will expand on it tomorrow

I understand the part about not leaving the form blank after initial submission and having the original submitted values now present in the fields. However, what I do not get is:

1. How to display the whole form again after submission.2. How to place the so-called 'red error messages' at the top of the form.3. My form is quite long, should I perhaps split it up into a two page form. For example, form 1 - enter username, password, e-mail, if that is validated okay, go to form 2 and enter rest of profile details, then submit and the member has joined.4. I am also implementing client-side Javascript and that should take care of most errors, hence, I shouldn't really make much of a fuss over this should I?

When using FORMS I do things in 2 parts. The first part displays the FORM asking user to fill it in and submit it.

In which case the first part is the first function. The second part - error validation and db dump is taken by a second function.

This is all you need. If you have any errors, void the db dump and re-create the FORM again (from second function) though for the FORM elements which have errors, you leave these blank and if an element is okay, you put back the value (from $_POST).

The user submit's the FORM again with correct details and again you reload the page.

The page detects (using some script you write - later) the FORM submission and again checks validation etc - using the second function.

Now to know the difference between a FORM submission or not I use:

PHP Code:

if(isset($_FORM['SubmittedForm'])) {# form has been submitted so# check validation etc} else {# display form for user to complete}

Last weekend, what you said did make sense.. but it seems a bit hazy now.. sorry!

My script structure is as follows:

PHP Code:

<?php if (isset($_POST['submit'])) { // a new member joins using the form below// Form validationelse { // If validation is all TRUE, then enter a record into DB} } else { // Drop-down box queries?>// Start FORM...// End FORM<?php} // end if main if else statement for if the form has been submitted?>

Good weekend - thanks 8) The weather up here in the North was good as well 8)

Makes a bloody change since it was raining like there were no tomorrow on Fri....

About your problem though, I have posted some script to help you understand some more.

Though for the moment, the script doesn't put the correct values back to the form in the event of one or more bad user inputs - i.e. invalid characters.

Instead the form is simply displayed again - it's a login basically and I don't like to see the password passed along again if it's correct and the username isn't - I want the user to re-type both the username/password again so just to be sure a user is exactly who they say they are 8)