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
7 2122
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.
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. -
<?php require_once('Connections/userstatesTest.php'); ?>
-
<?php require_once('Connections/enumTest.php'); ?>
-
<?php
-
if (!function_exists("GetSQLValueString")) {
-
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
-
{
-
if (PHP_VERSION < 6) {
-
$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 users (users_id, users_name, states_id) VALUES (%s, %s, %s)",
-
GetSQLValueString($_POST['users_id'], "int"),
-
GetSQLValueString($_POST['users_name'], "text"),
-
GetSQLValueString($_POST['states_id'], "int"));
-
-
mysql_select_db($database_enumTest, $enumTest);
-
$Result1 = mysql_query($insertSQL, $enumTest) or die(mysql_error());
-
}
-
-
mysql_select_db($database_userstatesTest, $userstatesTest);
-
$query_Recordset1 = "SELECT * FROM states";
-
$Recordset1 = mysql_query($query_Recordset1, $userstatesTest) or die(mysql_error());
-
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
-
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
-
?>
-
<!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>Untitled Document</title>
-
</head>
-
-
<body>
-
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
-
<table align="center">
-
<tr valign="baseline">
-
<td nowrap="nowrap" align="right">Users_id:</td>
-
<td><input type="text" name="users_id" value="" size="32" /></td>
-
</tr>
-
<tr valign="baseline">
-
<td nowrap="nowrap" align="right">Users_name:</td>
-
<td><input type="text" name="users_name" value="" size="32" /></td>
-
</tr>
-
<tr valign="baseline">
-
<td nowrap="nowrap" align="right">States_id:</td>
-
<td><select name="states_id">
-
<?php
-
do {
-
?>
-
<option value="<?php echo $row_Recordset1['states_name']?>" ><?php echo $row_Recordset1['states_name']?></option>
-
<?php
-
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
-
?>
-
</select></td>
-
</tr>
-
<tr> </tr>
-
<tr valign="baseline">
-
<td nowrap="nowrap" align="right"> </td>
-
<td><input type="submit" value="Insert record" /></td>
-
</tr>
-
</table>
-
<input type="hidden" name="MM_insert" value="form1" />
-
</form>
-
<p> </p>
-
</body>
-
</html>
-
<?php
-
mysql_free_result($Recordset1);
-
?>
-
-
-
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 -
| states | CREATE TABLE `states` (
-
`states_id` bigint(20) NOT NULL DEFAULT '0',
-
`states_name` varchar(255) DEFAULT NULL,
-
PRIMARY KEY (`states_id`)
-
) ENGINE=InnoDB
-
here is the users table -
| users | CREATE TABLE `users` (
-
`users_id` bigint(20) NOT NULL DEFAULT '0',
-
`users_name` varchar(20) DEFAULT NULL,
-
`states_id` bigint(20) NOT NULL DEFAULT '0',
-
PRIMARY KEY (`users_id`,`states_id`),
-
KEY `states_id` (`states_id`),
-
CONSTRAINT `users_ibfk_1` FOREIGN KEY (`states_id`) REFERENCES `states` (`states_id`) ON DELETE CASCADE ON UPDATE CASCADE
-
) ENGINE=InnoDB
-
thanks again for your help!
also, states is a list table with a 1 => 8 to users.
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 misunderstanding your problem?
the drop down wont display the name of the state if i pass it the state id, unless you know how?
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
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |