954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Populating a fields on a form base on a selected item from a droplist.


<?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 .= " $event_code";
}

switch($value){

case "Add":
print "Added..........";
break;

case "Update":
print "Updated..........

";
break;

case "Delete":
print "Deleted..........

";
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 .......

";
break;
}
?>

Events

Event Code:

<? echo "$option_block"; ?>

Title:

Duration:

Grade:

Type:

Short Description:

Long Description:

Road End Number:


<?
// mysql_close($connection);
?>

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I have solve the following error by declaring $option_block = ''; at the top.

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

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

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.

Gary King
PHP/vBulletin Guru
Team Colleague
417 posts since Nov 2003
Reputation Points: 53
Solved Threads: 5
 

Thanks Gary. Any solutions for my queries. Query 1 is vital at this state.

ta

tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
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 .= " $event_code";
}
.
.
.

.
.
Event Code:

<? echo "$option_block"; ?>

.
.

SOS ta

tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

help! help! help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! anyone

tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You