473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php drop down menu help

201 New Member
hello -

i've created a drop down menu in dreamweaver, it selects my states from a list table that i have for users table.

I went from enum to list table and created a fk to the parent table.

i'm use to doing in access a lookup filed to a list this is what i'm trying to pretty much accomplish.

i'm able to pull the data no problem. just when it goes to insert into the child table to states it errors. cannot add or update a child row. because it's trying to insert the wrong data type.

how can i query both items from the parent and insert only the selected states primary_id not name into the child table?

thanks in advance for your help
Feb 18 '09 #1
7 2136
6,050 Recognized Expert Expert
Can you provide the code you have used to try this. Also, any error messages and any info that could be useful. Also, maybe an example (in concise english) of what the outcome should be.
Feb 18 '09 #2
201 New Member
sorry i've been up late programming and kind!

1. create a drop down list.
2. when the item is selected, insert it's id, not name into the table

I'm able to query the database for the drop down menu items, but i can't think of a way to insert the id and not the item name.

Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/userstatesTest.php'); ?>
  2. <?php require_once('Connections/enumTest.php'); ?>
  3. <?php
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  6. {
  7.   if (PHP_VERSION < 6) {
  8.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  9.   }
  11.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  13.   switch ($theType) {
  14.     case "text":
  15.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  16.       break;    
  17.     case "long":
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  35. $editFormAction = $_SERVER['PHP_SELF'];
  36. if (isset($_SERVER['QUERY_STRING'])) {
  37.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  38. }
  40. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  41.   $insertSQL = sprintf("INSERT INTO users (users_id, users_name, states_id) VALUES (%s, %s, %s)",
  42.                        GetSQLValueString($_POST['users_id'], "int"),
  43.                        GetSQLValueString($_POST['users_name'], "text"),
  44.                        GetSQLValueString($_POST['states_id'], "int"));
  46.   mysql_select_db($database_enumTest, $enumTest);
  47.   $Result1 = mysql_query($insertSQL, $enumTest) or die(mysql_error());
  48. }
  50. mysql_select_db($database_userstatesTest, $userstatesTest);
  51. $query_Recordset1 = "SELECT * FROM states";
  52. $Recordset1 = mysql_query($query_Recordset1, $userstatesTest) or die(mysql_error());
  53. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  54. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  55. ?>
  56. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  57. <html xmlns="http://www.w3.org/1999/xhtml">
  58. <head>
  59. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  60. <title>Untitled Document</title>
  61. </head>
  63. <body>
  64. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  65.   <table align="center">
  66.     <tr valign="baseline">
  67.       <td nowrap="nowrap" align="right">Users_id:</td>
  68.       <td><input type="text" name="users_id" value="" size="32" /></td>
  69.     </tr>
  70.     <tr valign="baseline">
  71.       <td nowrap="nowrap" align="right">Users_name:</td>
  72.       <td><input type="text" name="users_name" value="" size="32" /></td>
  73.     </tr>
  74.     <tr valign="baseline">
  75.       <td nowrap="nowrap" align="right">States_id:</td>
  76.       <td><select name="states_id">
  77.         <?php 
  78. do {  
  79. ?>
  80.         <option value="<?php echo $row_Recordset1['states_name']?>" ><?php echo $row_Recordset1['states_name']?></option>
  81.         <?php
  82. } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  83. ?>
  84.       </select></td>
  85.     </tr>
  86.     <tr> </tr>
  87.     <tr valign="baseline">
  88.       <td nowrap="nowrap" align="right">&nbsp;</td>
  89.       <td><input type="submit" value="Insert record" /></td>
  90.     </tr>
  91.   </table>
  92.   <input type="hidden" name="MM_insert" value="form1" />
  93. </form>
  94. <p>&nbsp;</p>
  95. </body>
  96. </html>
  97. <?php
  98. mysql_free_result($Recordset1);
  99. ?>
error message was child constraint, that because it's trying to insert the name, not id into the child table.

i have a states table
Expand|Select|Wrap|Line Numbers
  1. | states | CREATE TABLE `states` (
  2.   `states_id` bigint(20) NOT NULL DEFAULT '0',
  3.   `states_name` varchar(255) DEFAULT NULL,
  4.   PRIMARY KEY (`states_id`)
  5. ) ENGINE=InnoDB
here is the users table

Expand|Select|Wrap|Line Numbers
  1. | users | CREATE TABLE `users` (
  2.   `users_id` bigint(20) NOT NULL DEFAULT '0',
  3.   `users_name` varchar(20) DEFAULT NULL,
  4.   `states_id` bigint(20) NOT NULL DEFAULT '0',
  5.   PRIMARY KEY (`users_id`,`states_id`),
  6.   KEY `states_id` (`states_id`),
  7.   CONSTRAINT `users_ibfk_1` FOREIGN KEY (`states_id`) REFERENCES `states` (`states_id`) ON DELETE CASCADE ON UPDATE CASCADE
  8. ) ENGINE=InnoDB 

thanks again for your help!
Feb 18 '09 #3
201 New Member
also, states is a list table with a 1 => 8 to users.
Feb 18 '09 #4
6,050 Recognized Expert Expert
My eyes hurt. Anyway, why not pass the states ID instead of it's name to the value attribute of the drop down. Or am I misunderstandin g your problem?
Feb 18 '09 #5
201 New Member
the drop down wont display the name of the state if i pass it the state id, unless you know how?
Feb 18 '09 #6
201 New Member
ok i've got it accomplished thanks for your help.

it was a setting on the app side that i need to call entity states_name, but get the states_id value for insert
Feb 18 '09 #7
6,050 Recognized Expert Expert
Glad you got it working.

- Markus.
Feb 18 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

by: vikram.cvk | last post by:
Hello Experts, Im trying to design a CSS vertical drop down menu which should have the following functionality. Home About Us | -->Overview
by: rajat | last post by:
Hi, I have adapted a drop down menu from USC webpage (www.usc.edu). The link to my page is http://www-scf.usc.edu/~swarup/test/test.html The links to the CSS ans JS files are: http://www-scf.usc.edu/~swarup/test/Templates/dropdown.css http://www-scf.usc.edu/~swarup/test/Templates/default.js The problem I'm facing is that in IE 6 when the...
by: hemanth.singamsetty | last post by:
Hello there, I've a drop down menu (created using CSS & Javascript -- see code below). My problem is, whenever I click a link on the menu the new page replaces the current page (and the menu disappears). Is there a way, I can keep the menu always on top. ( A good example of what I'm looking for is similar to the menu bar in...
by: simon.cigoj | last post by:
I have an javascript made menu and some forms with the dropdown element. When the menu opens and scrolls down the drop down is displeyed over the menu and obscures the menu choices. I have this problem only in IE, in firefox it works ok. Is there a solution to this problem? I tried to hide the drop down when the menu opens but sometimes...
by: Andy Munnis | last post by:
Need help with creating a drop down menu. I am trying to replicate the GUI of a large db application that runs on large Sun servers using Oracle/Solaris, etc. My purpose is to create a stand-alone training package using Access that people can run on a laptop to simulate as near as possible the GUI of the real system. My problem is that the...
by: Reb | last post by:
Hi, I am using drop down menu in my pages. In one of my page,there is a listbox control below the menu. This listbox control is hiding the drop down menu items. How can i make the drop down menu not to be hidden by the listbox control? I tried to increase the z-index for the menu control. But it did not help.
by: StevePBurgess | last post by:
Hi I am using a drop down menu adapted from the one in Stylin with CSS by Charles Wyke Smith. The CSS is below. It works perfectly in Internet Explorer (using the csshover behaviour file) but in Firefox (and presumably other standards compliant browsers) it indents the menu on the screen then indents the drop down box by (seemingly) the...
by: rsteph | last post by:
I have a javascript drop down menu that I borrowed from a website. It utilizes a little .css to help with formatting. The menu works great, and on all 3 of the browsers I'm concerned about; but I am having one problem. The menu, as designed, is a 1-tier menu (or is it 2-tier). It has the horizontal menu bar, along with the drop downs... but the...
by: ponyeyes | last post by:
Hi There, I am a bit of a newbie to PHP programming and I would like to know how I can place a selected drop down option into a PHP variable and then produce an sql query which incorporates this variable. I have created a dynamic drop down menu that populates itself with data from a MySQL table. I now want it to populate a second drop-down...
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me if it works, and if it does not, tell me why it does not work. Thanks.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.