Page 1 of 1

Populating a edit-delete form with data

Posted: Fri Oct 27, 2006 1:35 am
by SoreE yes
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).

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

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>

Posted: Fri Oct 27, 2006 6:31 pm
by RobertGonzalez
Moved to PHP - Code.

You PHP code is not setting the var in the link properly. Try this.

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) or die(mysql_error());

while ($record=mysql_fetch_array($result)) {
    echo '<a href="Edit_Delete_One.php?EventID=' . $record['eventID'] . '">';
    echo"<br>";
}
?>

It works!

Posted: Wed Nov 01, 2006 2:58 am
by SoreE yes
Thanks, it worked like a dream.