Forum Moderators: coopster
This is how the site works
1st page (index.php) has a drop down list with 4 options -
(user1, user2,user3,user4) and a submit button
2nd page (mainpage.php) uses the name of the user selected in page1 to display a message "Welcome userName" using following script
Welcome <?php echo "$_POST['user']"; ?>
2nd page also displays two forms - having 1 submit button each which are "Add new contact" and "Search for contacts"
What I want is a separate database for the 4 users, and the the contact must be added to and searched from only that database which corresponds to the user selected on Page1
How can I carry forward the user selected on Page1 to Page3 and 4 ie. "Add contact" and "Search" ?
Thanks!
How can I carry forward the user selected on Page1 to Page3 and 4 ie. "Add contact" and "Search" ?
You need to store the user in either a session [uk.php.net] variable or a cookie in order to maintain state between page requests.
<added>
Cookies, hidden form input, query string are indeed other options, didn't mean to discount them. Determine the best solution for your particular application. You'll likely find yourself using one or more of them for different applications.
</added>
I used a series of if and else if statements so that each user inputs data only into his separate table(whose name is same as that of the user)..
Just out of curiosity and to reduce coding, is it possible to directly refer to the table using $_POST["user"]..
the name of the user and the name of the table being the same
As in something like this-
$sql="INSERT INTO $_POST["user"] (... )VALUES ( ....)";
Also, there is a text field to accept an email address.. the column type in mysql table is varchar. But the email column in Mysql rremains NULL even if some email address is entered. What can be the problem here?
You likely have your code incorrect for the email issue. Dump the query and/or the data back to your browser after you have assembled the sql query and before you execute it.
And Sorry but didnt get your solution for the email issues.. what is meant by 'dumping the query to the browser' ?
i have a drop down list with 4 usernames..(fixed) so I dont think 'mysql' can be passed in anyway ( or can it still be passed? )
Yes, it could still be passed... in a live environment, a hacker (or even an automated robot/script) would probably bypass your form completely and send a POST request directly to your script (all client side HTML/JavaScript would be bypassed).