•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,691 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,206 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 401 | Replies: 8
![]() |
•
•
Join Date: Jun 2008
Posts: 44
Reputation:
Rep Power: 1
Solved Threads: 0
hey frnds...
i am develpoing a program using PHP/MySQL. Here, i have a form which consists of a few text fields etc etc. It also contains a drop down menu.
In the backend, i have a number of databases. The user input (drop down menu) will decide which database is connected to.
Please help me with the code for the same. I want to strict to PHP/TML only, and not use javascript.
pls help.
thx..
i am develpoing a program using PHP/MySQL. Here, i have a form which consists of a few text fields etc etc. It also contains a drop down menu.
In the backend, i have a number of databases. The user input (drop down menu) will decide which database is connected to.
Please help me with the code for the same. I want to strict to PHP/TML only, and not use javascript.
pls help.
thx..
Hi,
I just want to say that Iv only been doing php for a few days now but i think i can give you a good answer.
You want a drop down menu which decides which database the next page connects to only using html and php?
Form page:
Action page:
I hope that answered your question =]
ps. the only thing im not 100% sure about is the format of this bit:
So if it dosnt work that is the section that is most likely to be wrong. Maybe ask somebody else or try
mysql_select_db($dbchoice)
I just want to say that Iv only been doing php for a few days now but i think i can give you a good answer.
You want a drop down menu which decides which database the next page connects to only using html and php?
Form page:
<form id="connect" name="connect" method="post" action="connect.php">
<select name="dbchoice" id="dbchoice">
<option value="db1">db1</option>
<option value="db2">db2</option>
<option value="db3">db3</option>
</select>
</form>Action page:
<?php
$dbchoice = $_POST['$dbchoice'];
//the above line gets the value from the drop down box on the previous page
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("$dbchoice") or die(mysql_error());;
//above this text NOW where it sayd $dbchoice, the server is writting in the value from the drop down form from the previous page. this means that the database chosen is the one with the same name as what the user chose on the form.
?>I hope that answered your question =]
ps. the only thing im not 100% sure about is the format of this bit:
mysql_select_db("$dbchoice") So if it dosnt work that is the section that is most likely to be wrong. Maybe ask somebody else or try
mysql_select_db($dbchoice)
Economizerz Hosting
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
•
•
Join Date: Jun 2008
Posts: 44
Reputation:
Rep Power: 1
Solved Threads: 0
hey... thanks for replying....
i think your solution should also work....
but i was trying in the meantime, and came upon a solution.
i make the form as usual (that was never a point f debate)
then, in the ACTION-PAGE of the form, i use an "if-else" clause.
meaning that i first store the value of the drop-down into a variable, and then i use a simple if-elseif-else clause.
CODE
$dbchoice = $_POST['$dbchoice'];
if($dbchoice == 1)
{
mysql_connect(....db1....)
}
else if($dbchoice ==2)
{
mysql_connect(....db2....)
}
and so on..
this solution has worked for me...
i'll try urs as well, though i dont ssee any eason why it should'nt work...
i think your solution should also work....
but i was trying in the meantime, and came upon a solution.
i make the form as usual (that was never a point f debate)
then, in the ACTION-PAGE of the form, i use an "if-else" clause.
meaning that i first store the value of the drop-down into a variable, and then i use a simple if-elseif-else clause.
CODE
$dbchoice = $_POST['$dbchoice'];
if($dbchoice == 1)
{
mysql_connect(....db1....)
}
else if($dbchoice ==2)
{
mysql_connect(....db2....)
}
and so on..
this solution has worked for me...
i'll try urs as well, though i dont ssee any eason why it should'nt work...
Okay
Glad you got things working.
Glad you got things working. Economizerz Hosting
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
<?php
$dbchoice = $_POST['$dbchoice'];
//the above line gets the value from the drop down box on the previous page
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("$dbchoice") or die(mysql_error());;
//above this text NOW where it sayd $dbchoice, the server is writting in the value from the drop down form from the previous page. this means that the database chosen is the one with the same name as what the user chose on the form.
?><?php
$dbchoice = $_POST['$dbchoice'];
//the above line gets the value from the drop down box on the previous page
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("$dbchoice") or die(mysql_error());;
//above this text NOW where it sayd $dbchoice, the server is writting in the value from the drop down form from the previous page. this means that the database chosen is the one with the same name as what the user chose on the form.
?> This is Good ay for Multi Selecting
$dbchoice = $_POST['$dbchoice'];
//the above line gets the value from the drop down box on the previous page
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("$dbchoice") or die(mysql_error());;
//above this text NOW where it sayd $dbchoice, the server is writting in the value from the drop down form from the previous page. this means that the database chosen is the one with the same name as what the user chose on the form.
?><?php
$dbchoice = $_POST['$dbchoice'];
//the above line gets the value from the drop down box on the previous page
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("$dbchoice") or die(mysql_error());;
//above this text NOW where it sayd $dbchoice, the server is writting in the value from the drop down form from the previous page. this means that the database chosen is the one with the same name as what the user chose on the form.
?> This is Good ay for Multi Selecting
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
amd avatar backup blue gene breach business c++ chips daniweb data data protection database development dos economy energy enterprise erp systems europe evaluation government hardware hp ibm ibm. news intel ibm it linux medicine memory microsoft mmorpg mysql news open source openoffice pc pirate ps3 red hat security server software solutions sun supercomputer supercomputing trends ubuntu working x86
- Previous Thread: need help with WAMP5
- Next Thread: selecting data using multiple conditions


Linear Mode