Page 1 of 1

I got a few form/mysql related questions

Posted: Sun May 30, 2004 9:44 am
by Xephon
ok i am trying to make a CMS/Forum setup, but i have a few questions.

1) How do i setup the form, so that if they mess up, and get redirected back to it because, say they typed in an inuse username, how do i keep all the info they already posted in the other field so they dont have to retype anything except the username.

2) how do i handle the mysql query of a form that has optional feilds, because if i make a query like this

Code: Select all

mysql_query("insert into users (username, email_address, password,
                          first_name, last_name, info, signup_date) values ('$username','$email_address',
                          '$password','$first_name','$last_name','$info', now())");
and the first_name, last_name, and info are all optional, the query would mess up since they would not be defined. so what kind of code would i need to make it handle them maybe being blank?

i know ill think of more questions lol, ill just keep adding them here.

thx in advance

Posted: Sun May 30, 2004 10:28 am
by kettle_drum
1) Create a form on the page that shows the error with the correct values in hidden fields. And then on the original form that you go back to have:

Code: Select all

<input type="text" name="blah" value="<?php if(isset($_POST['blah'])){echo $_POST['blah']}?>"
2) Just make sure you define all the variables, even if they are just blank.