Jump to content

Selecting A Db To Insert Data With Php And Mysql


kfordham281
 Share

Recommended Posts

Bascially here's the situation. I've got a form feeding data to a mysql db which contains data that is feeding a googlemap that I've made. The website will have two of these google maps displaying different data and in different databases (same table/field structure in each db). I'd like to have one form to post the data (easier to maintain, less files, etc) so I need a way to select the database in the form so that the data gets sent to the right db.

 

I've got includes which have the functions of opening the db, closing the db, and configuration of the db. I've commented out the db name in the config include ($dbname) and I'm trying to use a drop down to select the correct db. When I do this, I'm getting a "Error, insert query failed" error. It's likely because it doesn't know the db name to use. Can anyone help?

 

Here is the code for the select statement. I'll gladly post any other code if necessary.

 

><select name="dbname" id="$dbname">
	  <option value="">Please Select ...</option>
	  <option value="databasenameone">Ultra O-gaine</option>
	  <option value="databasenametwo">Adventure24</option>
	</select>

 

I'm basically a complete php newbie. I've been able to hack away at things thus far with finding code and tutorials on the net and adapting it to my situation but this one I can't seem to get right. Any help is much appreciated. Thanks!

Link to comment
Share on other sites

Testing this:

<html>

<!-- select.php -->

<body>

<FORM action="select.php" method="post">

<select name="dbname" id="<?php echo $dbname;?>">

<option value="">Please Select ...</option>

<option value="databasenameone">Ultra O-gaine</option>

<option value="databasenametwo">Adventure24</option>

</select>

<input type="submit" name="submit" value="Try Me!">

</form>

<?php echo $dbname;?>

</body>

</html>

 

Seems to work correctly. Unless you are printing the whole form with a php print statement, you need to break into php to put your variable in the there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...