Jump to content

Form with drop down list (Newbie Needs a lot of help)


junk4u

Recommended Posts

Okay, you guys were great on the last posting I have as I’m just learning a little bit at a time on my spare time.

I am trying to figure out several things in this test.

 

1)How to use multiple tables:

a)Table1: Registration (standard creation of a form to DB.)

b)Table2: countries

c)How to setup a drop down list retrieving data from the table countries

2)I am running local as always with the following specs.

a)Windows Home Prem

b)Wampserver with Apache 2.2.17, MySQL 5.5.8, and PHP 5.3.5

 

 

I use www.turningturnip.co.uk to create the basic php to MySQL form, but they don’t have basic creating a dropdown list from a table in mysql DB.

 

connect.php

 

<?php

/// For the following details,

/// please contact your server vendor

 

$hostname='localhost'; //// specify host, i.e. 'localhost'

$user='root'; //// specify username

$pass=''; //// specify password

$dbase='competitors'; //// specify database name

$connection = mysql_connect("$hostname" , "$user" , "$pass")

or die ("Can't connect to MySQL");

$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

?>

 

 

 

add.php

 

<form id="FormName" action="added.php" method="post" name="FormName">

<table width="448" border="0" cellspacing="2" cellpadding="0">

<tr><td width = "150"><div align="right"><label for="name">name</label></div></td>

<td><input id="name" name="name" type="text" size="25" value="" maxlength="50"></td></tr><tr><td width = "150"><div align="right"><label for="address">address</label></div></td>

<td><input id="address" name="address" type="text" size="25" value="" maxlength="30"></td></tr>

 

<tr><td width = "150"><div align="right"><label for="countries">country</label></div></td>

<td><select id="country" name="country" size="1">

<option value="one">first</option>

<option value="two">second</option>

</select></td></tr>

 

<tr><td width = "150"><div align="right"><label for="telephone">Telephone</label></div></td>

<td><input id="telephone" name="telephone" type="text" size="25" value="" maxlength="10"></td></tr><tr><td width="150"></td><td>

<input type="submit" name="submitButtonName" value="Add"></td>

</tr></table></form>

 

 

added.php

 

<a href="index.php">Back to List</a>

<?php

/// In order to use this script freely

/// you must leave the following copyright

/// information in this file:

/// Copyright 2006 www.turningturnip.co.uk

/// All rights reserved.

 

include("connect.php");

$name = trim($_POST['name']);

$address = trim($_POST['address']);

$country = trim($_POST['country']);

$telephone = trim($_POST['telephone']);

 

$query = "INSERT INTO registration (id, name, address, country, telephone)

VALUES ('', '$name', '$address', '$country', '$telephone')";

$results = mysql_query($query);

 

if ($results)

{

echo "Details added.";

}

mysql_close();

?>

 

 

 

 

 

COUNTRY TABLE:

--

-- Table structure for table `countries`

--

 

CREATE TABLE `countries` (

  `ccode` varchar(2) NOT NULL default '',

  `country` varchar(200) NOT NULL default '',

  PRIMARY KEY  (`ccode`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

--

-- Dumping data for table `countries`

--

 

INSERT INTO `countries` VALUES ('AF', 'Afghanistan');

INSERT INTO `countries` VALUES ('AX', 'Åland Islands');

INSERT INTO `countries` VALUES ('AL', 'Albania');

INSERT INTO `countries` VALUES ('DZ', 'Algeria');

INSERT INTO `countries` VALUES ('AS', 'American Samoa');

 

 

 

If anyone could help as being a newbie to all this it's all trial and error for me and I've tried every way that I found possible to set it up and haven't been successful. I also reviewed many posting similar problems, but i can't seem to get it going.

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.