Could someone help me with the following?
I have a form which is used to collect user information, one of the fields I require is Country. I have set up a table in my database with details of all countries and a country ID.
I would like to populate a drop box with these countries and then when I load form.php which appends this data to the the database for the script to append the Country ID to the database.
I have included the HTML form I am using and form.php.
HTML FORM
Code: Select all
<HTML>
<HEAD>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<TITLE>Registration Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="form.php" METHOD="post">
Please provide the following contact information:</P>
<BLOCKQUOTE>
<TABLE>
<TR>
<TD ALIGN="right">
<EM>Title</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="Title" SIZE=35>
</TD>
</TR>
<TR>
<TD ALIGN="right">
<EM>First Name</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="FirstName" SIZE=35>
</TD>
</TR>
<TR>
<TD ALIGN="right">
<EM>Middle Name</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="MiddleName" SIZE=35>
</TD>
</TR>
<TR>
<TD ALIGN="right">
<EM>Last Name</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="LastName" SIZE=35>
</TD>
</TR>
<TR>
<TD ALIGN="right">
<EM>E-mail</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="Email" SIZE=25>
</TD>
</TR>
<TR>
</TR>
<TR>
<TD ALIGN="right">
<EM>Organization</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="Organization" SIZE=36></TD>
</TR>
<TR>
<TD ALIGN="right">
<em>Address</em></TD>
<TD>
<INPUT TYPE=TEXT NAME="Address1" SIZE=35></TD>
</TR>
<TR>
<TD ALIGN="right">
<em>Address</em></TD>
<TD>
<INPUT TYPE=TEXT NAME="Address2" SIZE=35></TD>
</TR>
<tr>
<TD ALIGN="right">
<em>City</em></TD>
<TD>
<INPUT TYPE=TEXT NAME="City" SIZE=35></TD>
</tr>
<tr>
<TD ALIGN="right">
<em>State/County</em></TD>
<TD>
<INPUT TYPE=TEXT NAME="County" SIZE=35></TD>
</tr>
<TR>
<TD ALIGN="right">
<em>Post Code</em></TD>
<TD>
<INPUT TYPE=TEXT NAME="PostCode" SIZE=35></TD>
</TR>
<TR>
<TD ALIGN="right">
<em>Country</em></TD>
<TD>
<INPUT TYPE=TEXT NAME="Country" SIZE=35></TD>
</TR>
<TR>
<TD ALIGN="right">
<EM>Work Phone</EM></TD>
<TD>
<INPUT TYPE=TEXT NAME="Phone" SIZE=25 MAXLENGTH=25>
</TD>
</TR>
</TABLE>
</BLOCKQUOTE>
<INPUT TYPE=SUBMIT VALUE="Submit Form">
<INPUT TYPE=RESET VALUE="Reset Form">
</FORM>
</BODY>
</HTML>The country ID should be included where I have inserted the word COUNTRYID.
Code: Select all
<?php
include "config.php";
$table = "tblCustomer"; // database table
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$insert = mysql_query("insert into $table values ('', 0,'Web','".$_POST['Title']."', '".$_POST['FirstName']."', '".$_POST['MiddleName']."', '".$_POST['LastName']."', '".$_POST['Organisation']."','".$_POST['Address1']."', '".$_POST['Address2']."', 'Address3', '".$_POST['City']."', '".$_POST['PostCode']."', '".$_POST['State']."', 'COUNTRYID', '".$_POST['Email']."', '".$_POST['Phone']."','')", $link)
or die("Could not insert data because ".mysql_error());
mysql_close();
echo "Thank you for registering";
?>