Populating a edit-delete form with data
Posted: Fri Oct 27, 2006 1:35 am
I'm struggling, it's new territory.
I am able to pass over the variable with the URL, however was stuck with the unsatisfactory use of the fieldvalue for the eventID (a number rather than the field name).
The page that it is passed over to, has the following code, which selects the required row from the database for the event. The second part creates a form, that needs to be populated by this same data. That's where I am stuck.
I am able to pass over the variable with the URL, however was stuck with the unsatisfactory use of the fieldvalue for the eventID (a number rather than the field name).
Code: Select all
<?php $db=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("bobfrance") or die(mysql_error());
$query="SELECT date, location, course_details,therapy, eventID FROM event WHERE date>now()
ORDER by date";
$result=mysql_query($query);
while($record=mysql_fetch_row($result)) {
while(list($fieldname,$fieldvalue)=each($record)){
echo $fieldvalue.", ";
if ($fieldname=1) {$eventID=$fieldvalue;}
}
echo "<a href='Edit_Delete_One.php?EventID=$eventID'>";
echo"<br>";
}
?>Code: Select all
<?php require_once('../Connections/bobfrance.php'); ?>
<?
$EventID=$_GET['EventID'];
echo $EventID;
?>
<html>
<head>
<title>Edit/Delete Events</title>
</head>
<h1>Edit or Delete Event</h1>
<body>
<?php /*?>Select a row from database for one event<?php */?>
<?
$db=mysql_connect ("localhost") or die(mysql_error());
mysql_select_db("bobfrance") or die(mysql_error());
$query = "SELECT * FROM event WHERE eventID=$EventID";
$result=mysql_query($query);
while($record=mysql_fetch_row($result)) {
while(list($fieldname,$fieldvalue)=each($record)){
echo $fieldvalue.", ";
}
};
?>
<!--Create Form-->
<form id="form1" name="form1" method="post" action="ReplaceEnterEvent.php">
<br />
Select Therapy
<BR />
<select name="therapyID" >
<?php require_once('../Connections/bobfrance.php'); ?>
<?php
$db=mysql_connect ("localhost") or die(mysql_error());
mysql_select_db("bobfrance") or die(mysql_error());
$query = "SELECT * FROM therapy ORDER by therapy";
$result=mysql_query($query);
while ($record=mysql_fetch_assoc($result)) {
echo "<OPTION VALUE = '".$record["therapyID"]."'>".$record["therapy"];
}
?>
</select>
<BR />
<label>Date
<input type="text" name="date" value="$fieldvalue"/> <br />
</label>
<label>Course Details
<textarea name="coursedetails" rows="5"></textarea>
<br />
</label>
<label>Location
<select name="location" >
<Option value="Harrogate">Harrogate</Option>
<Option value="Sheffield">Sheffield</Option>
<Option value="London">London</Option>
</select>
</label>
<p>
<label>Replace
<input type="submit" name="Replace" value="Submit" />
</label>
</p>
</form>
</body>
</html>