I got a few form/mysql related questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Xephon
Forum Newbie
Posts: 20
Joined: Sat May 15, 2004 10:58 pm

I got a few form/mysql related questions

Post 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
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
Post Reply