Linking a Drop down menu option to a Mysql table.

Thread Solved

Join Date: Aug 2008
Posts: 8
Reputation: litchi is an unknown quantity at this point 
Solved Threads: 0
litchi litchi is offline Offline
Newbie Poster

Linking a Drop down menu option to a Mysql table.

 
0
  #1
Aug 29th, 2008
Hello there,

I am having trouble with a form/database. I have 3 age groups that needs to be sorted into 3 separate tables. Users fill in a form (dropdown list with the separate age groups) and when they click submit, the data gets sorted in tables on another page. With the help of dreamweaver I could get the list linked to 1 table, but can't get it to sort into the 3 different tables.

The DB's name is: "hotel"
The table's name is: "besprekings"
I would like to organize the data based on their choice in "Graad" (sorry for different language) (bolded area) so if they chose "10" their data would be sorted into the "graad 10" table and so on.

I hope I'm making sense..

Here's the code:

 <?php require_once('Connections/hotel.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO besprekings (`Naam en Van`, Epos, `Telefoon Nommer`, `Aantal Sitplekke`, Graad, Datum) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Naam_en_Van'], "text"),
                       GetSQLValueString($_POST['Epos'], "text"),
                       GetSQLValueString($_POST['Telefoon_Nommer'], "text"),
                       GetSQLValueString($_POST['Aantal_Sitplekke'], "text"),
                       GetSQLValueString($_POST['Graad'], "text"),
                       GetSQLValueString($_POST['Datum'], "text"));

  mysql_select_db($database_hotel, $hotel);
  $Result1 = mysql_query($insertSQL, $hotel) or die(mysql_error());

  $insertGoTo = "dankie.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>La Doraigne</title>
<link rel="stylesheet" type="text/css" href="css.css" media="screen" />
<script src="request.js"></script>
<script>
function handleOnChange(dd1)
{
  var idx = dd1.selectedIndex;
  var val = dd1[idx].text;
  var par = document.forms["form1"];
  var parelmts = par.elements;
  var prezsel = parelmts["Datum"];
  var Graad = val;
  if (Graad != "Kies graad")
  {
 	Http.get({
		url: "./" +  Graad + ".txt",
		callback: fillPrez,
		cache: Http.Cache.Get
	}, [prezsel]);
  }
}

function fillPrez(xmlreply, prezelmt)
{
  if (xmlreply.status == Http.Status.OK)
  {
    var prezresponse = xmlreply.responseText;
    var prezar = prezresponse.split("|");
    prezelmt.length = 1;
    prezelmt.length = prezar.length;
    for (o=1; o < prezar.length; o++)
    {
      prezelmt[o].text = prezar[o];
    }
  }
  else
  {
    alert("Cannot handle the AJAX call.");
  }
}
</script>
</head>

<body> 
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
    <table align="left">
      <tr valign="baseline">
        <td width="114" align="left" nowrap="nowrap">Naam en Van:</td>
        <td width="212"><input type="text" name="Naam_en_Van" value="" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="left">Epos:</td>
        <td><input type="text" name="Epos" value="" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="left">Telefoon Nommer:</td>
        <td><input type="text" name="Telefoon_Nommer" value="" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="left">Aantal Sitplekke:</td>
        <td><select name="Sitplekke">
			<option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>1</option>
            <option value="2" <?php if (!(strcmp(2, ""))) {echo "SELECTED";} ?>>2</option>
            <option value="3" <?php if (!(strcmp(3, ""))) {echo "SELECTED";} ?>>3</option>
            <option value="4" <?php if (!(strcmp(4, ""))) {echo "SELECTED";} ?>>4</option>
            <option value="5" <?php if (!(strcmp(5, ""))) {echo "SELECTED";} ?>>5</option>
            <option value="6" <?php if (!(strcmp(6, ""))) {echo "SELECTED";} ?>>6</option>
            <option value="7" <?php if (!(strcmp(7, ""))) {echo "SELECTED";} ?>>7</option>
            <option value="8" <?php if (!(strcmp(8, ""))) {echo "SELECTED";} ?>>8</option>
          	</select></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="left">Graad:</td>
        <td><select name="Graad" onChange="handleOnChange(this);">
<option>Kies graad</option>
<option value="10" <?php if (!(strcmp(10, ""))) {echo "SELECTED";} ?>>10</option>
<option value="11" <?php if (!(strcmp(11, ""))) {echo "SELECTED";} ?>>11</option>
<option value="12" <?php if (!(strcmp(12, ""))) {echo "SELECTED";} ?>>12</option>
</select>

        </td>      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="left">Datum:</td>
        <td></p><p>
		<select name="Datum">
		<option>Kies Datum</option>
		</select></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="left">&nbsp;</td>
        <td><input type="submit" value="Gaan Voort" /></td>
      </tr>
    </table>
    <input type="hidden" name="MM_insert" value="form1" />
  </form></p>
  </div>
</body>
</html>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: litchi is an unknown quantity at this point 
Solved Threads: 0
litchi litchi is offline Offline
Newbie Poster

Re: Linking a Drop down menu option to a Mysql table.

 
0
  #2
Aug 30th, 2008
Hi again,

I got it working

Simple if statement on receiving page. Sorry.

litchi
Last edited by litchi; Aug 30th, 2008 at 10:38 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC