•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,176 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,439 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 5682 | Replies: 5
![]() |
•
•
Join Date: Sep 2004
Posts: 13
Reputation:
Rep Power: 4
Solved Threads: 0
I am a second year IT student who is working on a project using PHP(frontend) and MySQL(backend). I am brand new to these softwares which are not being touch in class. I have 2 questions:
1. How do I populate fields (textboxes) in a html form from a selected item in a droplist. The droplist and fields in the form are from the same table. I have spend hours on this but seem to get no where.
2. How do I integrate the the above query into my code where I have add, update, and delete button on one page. The name of the page is add_event2.php
Table: events
-------------
event_code
title
duration
grade
type
desc_short
desc_long
<html>
<head><title>(Event Form)</title></head>
<body>
<?php
// db connectivity works
include 'db.php';
$tablename = 'events';
$value = "";
if (isset($_POST['submit'])){
$value = $_POST['submit'];
}
// create SQL statement
$sql = "SELECT event_code FROM $tablename ORDER BY event_code ASC";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$event_code = $row["event_code"];
// line gives an error but still copiles the list.
$option_block .= "<OPTION value=\"$event_code\"> $event_code</OPTION>";
}
switch($value){
case "Add":
print "Added..........<P>";
break;
case "Update":
print "Updated..........<P>";
break;
case "Delete":
print "Deleted..........<P>";
break;
case "": //first time to open this form.
//should populate fields in the form with the last record in the table event
print "First time to open this form .......<p>";
break;
}
?>
<form method="post" action="add_event2.php" ID="event_form">
<P><STRONG><U>Events</U></STRONG></P>
<P>Event Code: <br>
<SELECT name="$event_code">
<? echo "$option_block"; ?>
</SELECT>
<P>Title: <INPUT type="text" name="title"></P>
<P>Duration: <INPUT type="text" name="duration"></P>
<P>Grade: <INPUT type="text" name="grade"></P>
<P>Type: <INPUT type="text" name="type"></P>
<P>Short Description: <INPUT type="text" name="desc_short"></P>
<P>Long Description: <INPUT type="text" name="desc_long"></P>
<P>Road End Number: <INPUT type="text" name="road_end_id"></P>
<p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Add"
<p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Update"
<p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Delete"
</form>
<?
// mysql_close($connection);
?>
</body>
</html>
Note that the above codes produce this error meassage but still seems to work:
Notice: Undefined variable: option_block in :\inetpub\wwwroot\add_event2.php on line 25
I would appreciate help urgently. If there is a better way of writing the codes, pls feel free to show me.
Thanks
tip
1. How do I populate fields (textboxes) in a html form from a selected item in a droplist. The droplist and fields in the form are from the same table. I have spend hours on this but seem to get no where.
2. How do I integrate the the above query into my code where I have add, update, and delete button on one page. The name of the page is add_event2.php
Table: events
-------------
event_code
title
duration
grade
type
desc_short
desc_long
<html>
<head><title>(Event Form)</title></head>
<body>
<?php
// db connectivity works
include 'db.php';
$tablename = 'events';
$value = "";
if (isset($_POST['submit'])){
$value = $_POST['submit'];
}
// create SQL statement
$sql = "SELECT event_code FROM $tablename ORDER BY event_code ASC";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$event_code = $row["event_code"];
// line gives an error but still copiles the list.
$option_block .= "<OPTION value=\"$event_code\"> $event_code</OPTION>";
}
switch($value){
case "Add":
print "Added..........<P>";
break;
case "Update":
print "Updated..........<P>";
break;
case "Delete":
print "Deleted..........<P>";
break;
case "": //first time to open this form.
//should populate fields in the form with the last record in the table event
print "First time to open this form .......<p>";
break;
}
?>
<form method="post" action="add_event2.php" ID="event_form">
<P><STRONG><U>Events</U></STRONG></P>
<P>Event Code: <br>
<SELECT name="$event_code">
<? echo "$option_block"; ?>
</SELECT>
<P>Title: <INPUT type="text" name="title"></P>
<P>Duration: <INPUT type="text" name="duration"></P>
<P>Grade: <INPUT type="text" name="grade"></P>
<P>Type: <INPUT type="text" name="type"></P>
<P>Short Description: <INPUT type="text" name="desc_short"></P>
<P>Long Description: <INPUT type="text" name="desc_long"></P>
<P>Road End Number: <INPUT type="text" name="road_end_id"></P>
<p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Add"
<p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Update"
<p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Delete"
</form>
<?
// mysql_close($connection);
?>
</body>
</html>
Note that the above codes produce this error meassage but still seems to work:
Notice: Undefined variable: option_block in :\inetpub\wwwroot\add_event2.php on line 25
I would appreciate help urgently. If there is a better way of writing the codes, pls feel free to show me.
Thanks
tip
•
•
Join Date: Nov 2003
Location: Toronto, Canada
Posts: 354
Reputation:
Rep Power: 6
Solved Threads: 5
To turn off notices, you should set error_reporting() to something else; check www.php.net/error_reporting for more info
Your level is probably way too low; you should NEVER see Notice messages, they are only if you really want to debug things but about literally 95% of the time, notices are worthless.
Your level is probably way too low; you should NEVER see Notice messages, they are only if you really want to debug things but about literally 95% of the time, notices are worthless. •
•
Join Date: Sep 2004
Posts: 13
Reputation:
Rep Power: 4
Solved Threads: 0
These parts of my code produce a droplist which is populated by event_code field from the events table. But how do I populate the rest of the data on the form which an event_code is selected from droplist?
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$event_code = $row["event_code"];
// line gives an error but still copiles the list.
$option_block .= "<OPTION value=\"$event_code\"> $event_code</OPTION>";
}
.
.
.
<FORM...............>
.
.
<P>Event Code: <br>
<SELECT name="$event_code">
<? echo "$option_block"; ?>
</SELECT>
.
.
</FORM>
SOS ta
tip
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$event_code = $row["event_code"];
// line gives an error but still copiles the list.
$option_block .= "<OPTION value=\"$event_code\"> $event_code</OPTION>";
}
.
.
.
<FORM...............>
.
.
<P>Event Code: <br>
<SELECT name="$event_code">
<? echo "$option_block"; ?>
</SELECT>
.
.
</FORM>
SOS ta
tip
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Searching multiple fields... (PHP)
- Storing dynamic form values in Arrays for display & insert (PHP)
- Radiobuttonlist control - help! (ASP.NET)
- Populating & Retrieving Data in a listbox : ASP.NET (w/ VB.NET) (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: How do I install Sablotron with PHP?
- Next Thread: Converting Access Forms to PHP Forms


Linear Mode