Jump to content

Recommended Posts

Hi,

 

I've got a basic sign up form but I want a drop down list which will list different catergories that relate to different tables which when selected will input the sign up information into that table which was selected from the catergory drop down.

 

This is the signup form

 

<html><head><title>Birthdays Insert Form</title>

<style type="text/css">

td {font-family: tahoma, arial, verdana; font-size: 10pt }

</style>

</head>

<body>

<table width="300" cellpadding="5" cellspacing="0" border="2">

<tr align="center" valign="top">

<td align="left" colspan="1" rowspan="1" bgcolor="64b1ff">

<h3>Insert Record</h3>

<form method="POST" action="test.php">

<?

print "Enter Company Name: <input type=text name=company_name size=30><br>";

print "Enter Contact Name: <input type=text name=contact_name size=30><br>";

print "Enter Telephone: <input type=text name=telephone size=20><br>";

print "Enter Fax: <input type=text name=fax size=30><br>";

print "Enter Email: <input type=text name=email size=30><br>";

print "Enter Address: <input type=text name=address1 size=20><br>";

print "Enter Address: <input type=text name=address2 size=30><br>";

print "Enter Postcode: <input type=text name=postcode size=30><br>";

print "Enter Town / City: <input type=text name=town_city size=20><br>";

print "Enter Website: <input type=text name=website size=30><br>";

print "Enter Company Type: <select name='table'> <option>stationary</option><option>reception</option></select><br>";

print "<br>";

print "<input type=submit value=Submit><input type=reset>";

?>

</form>

</td></tr></table>

</body>

</html>

 

This is the part which I can't figure out and is probably totally wrong! Im trying to use this script to sort the drop down list to then run the correct script to insert the form data.

 

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

  <title>Hello!</title>

</head>

 

<body>

 

<?php

if($_POST['table']=='stationary' 'birthdays_insert_record.php')

 

else

 

if($_POST['table']=='reception' 'insert_reception.php')

?>

 

</body>

 

</html>

 

This is the script which works! that inserts the form data into a specific table

 

<html><head><title>Birthdays Insert Record</title></head>

<body>

<?

/* Change db and connect values if using online */

$company_name=$_POST['company_name'];

$contact_name=$_POST['contact_name'];

$telephone=$_POST['telephone'];

$fax=$_POST['fax'];

$email=$_POST['email'];

$address1=$_POST['address1'];

$address2=$_POST['address2'];

$postcode=$_POST['postcode'];

$town_city=$_POST['town_city'];

$website=$_POST['website'];

$db="myflawlesswedding";

$link = mysql_connect('localhost', 'root' , '');

if (! $link)

die(mysql_error());

mysql_select_db($db , $link) or die("Select Error: ".mysql_error());

$result=mysql_query("INSERT INTO reception (company_name, contact_name, telephone, fax, email, address1, address2, postcode, town_city, website) VALUES (

'$company_name',

'$contact_name',

'$telephone',

'$fax',

'$email',

'$address1',

'$address2',

'$postcode',

'$town_city',

'$website')") or die("Insert Error: ".mysql_error());

mysql_close($link);

print "Record added";

?>

<form method="POST" action="birthdays_insert_form.php">

<input type="submit" value="Insert Another Record">

</form>

<br>

 

<form method="POST" action="birthdays_dbase_interface.php">

<input type="submit" value="Dbase Interface">

</form>

 

 

 

</body>

</html>

 

I hope somebody can help me out here! or can point me in a better way to sort this problem!

 

Thanks for any advice!

Link to comment
https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/
Share on other sites

Try from this:

<?php
if($_POST['table']=='stationary' 'birthdays_insert_record.php')

else

if($_POST['table']=='reception' 'insert_reception.php')
?>

 

To this:

<?php
if($_POST['table']=='stationary') {
include('birthdays_insert_record.php'):
} elseif ($_POST['table']=='reception') {
include('insert_reception.php');
} else {
echo "Nothing was inserted";
}
?>

Ha, so it is, good eye.

 

Corrected:

 

<?php
if($_POST['table']=='stationary') {
include('birthdays_insert_record.php');
} elseif ($_POST['table']=='reception') {
include('insert_reception.php');
} else {
echo "Nothing was inserted";
}
?>

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.