Hi there,
I've essentially got a form with several drop down, each populated by columns in various tables.
The populating bit works fine - the column rows appear as they should in the menu.
Ideally the user needs to make their selections, and enter the form into a new database table.
The problem is, when the selection is entered into the new table, only the first word of the string is entered. For example, the drop down may have...
"Category One"
"Category Two"
"Category Three"
When the form is submitted only the word "Category" is entered into the database.
Here is the code, it takes the column 'courseTitle' from one table, displays it in a menu, and then saves the selection into a new table as 'eventName'. -
<?
-
include("connect.php");
-
$query="SELECT courseTitle FROM course";
-
$result = mysql_query ($query);
-
echo "<select name='eventName'=''></option>";
-
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
-
echo "<option value=$nt[courseTitle]>$nt[courseTitle]</option>";
-
}
-
echo "</select>";// Closing of list box
-
?>
-
Apologies if I've made it slightly long winded.
14 4339 dlite922 1,584
Recognized Expert Top Contributor
I don't know why you have an equal sign and extra quotes here: -
"<select name='eventName'=''></option>";
-
but debug your post vars like this
and see if the data gets there fine.
If that's fine, look in your insert SQL (not shown in your code). Just print it and see if it looks right.
If you don't find anything, post that code back here and any other notes/comments.
Apologies if I've made it slightly long winded.
Nope, it's perfect. I wish every user provided this concise amount of info.
Dan
Many thanks for the reply Dan,
I didn't notice the extra quotes. They made no difference either way.
The insert SQL is nothing special, I can't spot anything wrong with it. - <?
-
-
if($_POST['submit'])
-
{
-
include("connect.php");
-
-
$eventName = $_POST['eventName'];
-
$eventCategory1 = $_POST['eventCategory1'];
-
$eventCategory2 = $_POST['eventCategory2'];
-
$eventCategory3 = $_POST['eventCategory3'];
-
$eventLocation = $_POST['eventLocation'];
-
$eventDate = $_POST['eventDate'];
-
-
$result=MYSQL_QUERY("INSERT INTO events (eventName, eventCategory1, eventCategory2, eventCategory3, eventLocation, eventDate)".
-
"VALUES ('$eventName', '$eventCategory1', '$eventCategory2', '$eventCategory3', '$eventLocation', '$eventDate')");
-
-
echo "New Course Event Added";
-
}
-
?>
-
dlite922 1,584
Recognized Expert Top Contributor
echo $eventName right before the mysql_query() call, and print it's output. I don't know if you know this, but here's how I check my variables when I debug: - die(var_dump($eventname));
Another thing I can think of is your MySQL table definition. perhaps the field name is not long enough. ALTER TABLE and change that field to VARCHAR(100).
FYI: You can do "desc events" to give you a definition of the table from a mysql command prompt, if you have access to one.
Let me know,
Dan
I added the debug line on line 13 of the second script I posted - it returned the value "Null". The field is set to VARCHAR(100).
Was line 13 the right place to put it?
Markus 6,050
Recognized Expert Expert @Philth
That's because you probably did $eventname where it should be $eventName.
Anyway, var_dump() your POST array, to check it's being populated correctly by your form. -
var_dump($_POST);
-
// or
-
print_r($_POST);
-
Also, with your mysql_query()ies, while debugging, you're provided the function mysql_error() which is populated with a description of the latest mysql error (duh). So, as is popular, we append 'or die(mysql_error ());' to any mysql queries - some people don't like the 'or die()' statements, but it's purely preferential. -
mysql_query($query) or die(mysql_error());
-
Mark.
Mark,
Thanks for the reply.
The var_dump gave the following info...
array(7) { ["eventName"]=> string(6) "Master" ["eventCategory1 "]=> string(4) "VHDL" ["eventCategory2 "]=> string(4) "VHDL" ["eventCategory3 "]=> string(4) "VHDL" ["eventLocat ion"]=> string(7) "Germany" ["eventDate"]=> string(0) "" ["submit"]=> string(13) "Add New Event" }
Event name should read "Master VHDL Effectively".
I'm seriously confused.
Markus 6,050
Recognized Expert Expert
Ah, I see the problem: If you do not use quotes around an HTML attribute's value, it'll only read up to the first space as the value. Consider the following: -
<input value=my name is mark name=name />
-
// $_POST['name'] will hold the value 'my'.
-
<input value="my name is mark" name="name" />
-
// $_PSOT['name'] will hold "my name is mark"
-
Always surround attribute values with quotes.
Mark.
Hi Mark,
Apologies for not understanding. If the issue is to do with the values before being posted, then the error must be with the first script that I posted? -
<?
-
include("connect.php");
-
$query="SELECT courseTitle FROM course";
-
-
-
$result = mysql_query ($query);
-
echo "<select name='eventName'></option>";
-
-
while($nt=mysql_fetch_array($result)){
-
echo "<option value=$nt[courseTitle]>$nt[courseTitle]</option>";
-
-
}
-
echo "</select>";
-
?>
-
All HTML values are quoted.
Dormilich 8,658
Recognized Expert Moderator Expert @Philth
quoted?
............... ...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jason |
last post by:
I have a client that would like to have drop down menus added to a nav
bar that is generated from MySQL. Is it possible to have a dynamically
driven DHTML menu from MySQL?
example link
http://www.msnbc.msn.com/Default.aspx?p1=0
|
by: Mike Wilcox |
last post by:
I use the following code snippet to build a drop down menu with the
results of a query. How can I set the initial value of this input based
on the result of another query?
What I am trying to do is update records in the data base. The field
WkEndDate is pulled along with the rest of the record and the drop down
menu is built from a table of valid WkEndDate values.
echo ("Weekend Date: <select name='WkEndDate'/> ");
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest version of this document can be found at:
http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
|
by: elyob |
last post by:
Hi,
I'm looking at storing snippets of details in MySQL about what credit cards
a business excepts. Rather than have a whole column for Visa, another for
Amex etc ... I am looking at having a column called payment types and
inserting multiple codes ... e.g. ViAmBcCa
Is this a good way of doing things? To me it'd be a lot cleaner and limit
amount of Db work to be done. Is this a sensible way in your opinion? What's
the best way of...
|
by: Angelos |
last post by:
Hello again,
I have this dynamic menu and I want to change the order of the menu items...
I added a column in the database wich has an integer value for ordering the
menuitems.
But the only way is by hardcoding them into the database.
I would like a way to sort them with drag-and-drop or with up/down arrows.
Do you think that except PHP & MYsql I will need Javascript as well ?
| |
by: tusaar |
last post by:
Hi all
I am in big need for a drop down menu created with php, mysql and ajax. Exactly, I need three drop down menu (Category, Subcategory and Item). The data of each drop down will come from Mysql.
Anybody can help me please.. I will be very much thankfull. Please help me and give me a proper solution for that ASAP.
Thanks
Tushar
|
by: Boujii |
last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu, but I am unable to store a variable for it.
Here is a rough copy of what I am making:
<html>
<head>
<title>Add New MySQL User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
|
by: dongletran06 |
last post by:
Hi,
Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input text" are successfully adding data to mysql. I just try first using the month as drop down. The month data type I used in mysql database is varchar. Im new in PHP please help me. Thanks
<?php /* Created on: 10/12/2006 */ ?>
<html>
<body>
<?php...
|
by: Atli |
last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users.
Anyone should be able to get through this without much trouble. Programming knowledge is not required.
Index
What is SQL?
Why MySQL?
Installing MySQL.
Using the MySQL command line interface
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |