Jump to content


Posting Edited Form

  • Please log in to reply
1 reply to this topic

#1 WendyLady

  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 15 June 2006 - 06:16 PM

Hello --

I'm working on an admin page that pulls values from MySQL into a pre-filled form, so that the administrator can make changes. Then when submitted, it updates the row in MySQL to be what is on the form.

One of the fields is a category checkbox list that is populated by a request from another table (the admin sets the categories & can change them, and users can select the categories they fit in).

To send this information to the database in a comma-separated string (so that it is in a text-searchable string for another part of the site), I have been using:
$description = implode(',', $_POST['category']);
when I call my variables.

HOWEVER, I can't figure out how to repopulate the checkbox list as checked where the user had checked it, so I am just printing the string of current categories & would like for these to ONLY be changed if new checkboxes are checked. Otherwise, I want it to NOT change that entry. I've been trying this (and similar other things):
if (isset($_POST['category']) && (strlen($_POST['category']) >= 1)) {
$description = implode(',', $_POST['category']);
Also tried:
if ($_POST['category'] != ""){
$description = implode(',', $_POST['category']);
but it keeps updating the field to empty if nothing is checked. I would appreciate your comments!


#2 howrandom

  • Members
  • PipPip
  • Member
  • 11 posts

Posted 15 June 2006 - 07:17 PM

hey there, i have done the kind of thing you want, im new to this so im not sure how to ecplain it but if you look at my code you may be able to see what pieces you need.

<body bgcolor="#FFFFCC" text="#006600" link="#0000FF" vlink="#0000FF" alink="#0000FF">


if($Submit2) {
$sql="UPDATE RB_Customer

SET Title = '$Title',
First_Name = '$First_Name',
Last_Name = '$Last_Name',
Age = '$Age',
Address_Line_1 = '$Address_Line_1',
Address_Line_2 = '$Address_Line_2',
City = '$City',
County = '$County',
Postcode = '$PostCode',
Telephone_Number = '$Telephone_Number',
E_Mail = '$E_Mail'
WHERE Cust_Number = '$Cust_Number'";

echo "$sql Record updated/edited!<p>";

if($Submit) {
$sql="SELECT * FROM RB_Customer WHERE Cust_Number='$ID'";


$myrow = mysql_fetch_array($result);

<form method = \"post\" action = \"updatecust2.php\">
Title:<input type = \"Text\" name=\"Title\" value='$myrow[11]'<BR>
First_Name:<input type = \"Text\" name=\"First_Name\" value='$myrow[1]'<BR>
Last_Name:<input type = \"Text\" name=\"Last_Name\" value='$myrow[2]'<BR>
Age:<input type = \"Text\" name=\"Age\" value='$myrow[3]'<BR>
Address_Line_1:<input type = \"Text\" name=\"Address_Line_1\" value='$myrow[4]'<BR>
Address_Line_2:<input type = \"Text\" name=\"Address_Line_2\" value='$myrow[5]'<BR>
City:<input type = \"Text\" name=\"City\" value='$myrow[6]'<BR>
County:<input type = \"Text\" name=\"County\" value='$myrow[7]'<BR>
Postcode:<input type = \"Text\" name=\"PostCode\" value='$myrow[8]'<BR>
Telephone_Number:<input type = \"Text\" name=\"Telephone_Number\" value='$myrow[9]'<BR>
E_Mail:<input type = \"Text\" name=\"E_Mail\" value='$myrow[10]'<BR>
Cust_Number:<input type = \"Text\" name=\"Cust_Number\" value='$myrow[0]'<BR>
<input type = \"Submit\" name=\"Submit2\" value = \"Enter Information\">

$result=mysql_query("SELECT * FROM RB_Customer",$db);

echo "<table border=1>\n";
echo "<TR>
<TD><h2>Customer Number</h2></TD>
<TD><h2>First Name</h2></TD>
<TD><h2>Last Name</h2></TD>
<TD><h2>Address Line 1</h2></TD>
<TD><h2>Address Line 2</h2></TD>
<TD><h2>Telephone Number</h2></TD>
<TD><h2>E-Mail Address</h2></TD>

while($myrow = mysql_fetch_array($result)){

echo "
echo "</table>\n";


<form method = "post" action = "<?php echo $PHP_SELF?>">
ID:<input type = "Text" name="ID"><BR>
<input type = "Submit" name="Submit" value = "Choose Record To Be Updated">


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users