Jump to content

Edit Information Page Issues


jlev89

Recommended Posts

Hi,

I am crafting a page that allows an entity to edit its "profile."  I need the profile information pulled from the mysql database and then pre-inserted into the various form fields so the organization can see what it has already entered and fill in the missing parts, or update old information.  I'm new to PHP, and there is something wrong with my code that gives me issues.

The variable "chapterid" is part of the URL, in this format: http://xxxxxxxx.com/edit.php?chapterid=001.  I have a column in the table that is called "chapterid," and the entry "001" corresponds to a chapter listing.  None of the forms are filled in when I visit the page.  Is there an issue with my code?

Thanks,
Jordan

[code]
<?
$username="XXXXXXXXXXXXXX";
$password="XXXXXXXXXXXXXX";
$database="XXXXXXXXXXXXXXX";
$chapterid=$GET_['chapterid'];

mysql_connect("XXXXXXXXXXXXXXXX",$username,$password);
@mysql_select_db($database) or die( "Unable to select database. Please contact the webmaster.");
$query="SELECT * FROM csite_main WHERE chapterid='$chapterid'";

$result=mysql_query($query);

$i=0;
while ($i < $num) {

$cpfirst=mysql_result($result,$i,"cpfirst");
$cplast=mysql_result($result,$i,"cplast");
$tcpemail=mysql_result($result,$i,"cpemail");
$chapter=mysql_result($result,$i,"chapter");
$advfirst=mysql_result($result,$i,"advfirst");
$advlast=mysql_result($result,$i,"advlast");
$advemail=mysql_result($result,$i,"advemail");
$nextmtg=mysql_result($result,$i,"nextmtg");
$chapterdescription=mysql_result($result,$i,"chapterdescription");
$chapternews=mysql_result($result,$i,"chapternews");
$specials=mysql_result($result,$i,"specials");
$lastupdated=mysql_result($result,$i,"lastupdated");
$nextmtgdate=mysql_result($result,$i,"nextmtgdate");
$nextmtgtime=mysql_result($result,$i,"nextmtgtime");
$nextmtgroom=mysql_result($result,$i,"nextmtgroom");

mysql_close();
$i++;
}

    echo '<form id="edit" name="edit" method="post" action="editprocess.php?chapterid='.$chapterid.'">';
echo '<input name="chapterid" type="hidden" value="'.$chapterid.'">';
echo 'Chapter (School) Name<br />';
echo '<input name="chapter" type="text" size="30" value="'.$chapter.'"> <br /><br />';
                      echo '<p>Chapter President First Name<br />';
echo '<input name="cpfirst" type="text" size="30" value="'.$cpfirst.'" /><br /><br />';
  echo 'Chapter President Last Name<br />';
  echo '<input name="cplast" type="text" size="30" value="'.$cplast.'" /><br /><br />';
  echo 'Chapter President E-Mail<br />';
  echo '<input name="cpemail" type="text" size="30" value="'.$cpemail.'" /><br /><br />';
  echo 'Teacher Advisor Prefix <br />';
  echo '<select name="advfirst" value="'.$advfirst.'" ><option>Dr.</option><option>Mr.</option><option>Ms.</option><option>Mrs.</option><option>Miss</option><option>Professor</option></select><br /><br />';
  echo 'Teacher Advisor Last Name<br />';
  echo '<input name="advlast" type="text" size="30" value="'.$advlast.'" /><br /><br />';
  echo 'Teacher Advisor E-Mail<br />';
  echo '<input name="advemail" type="text" size="30" value="'.$advemail.'" /><br /><br />';
  echo 'Next Meeting Date<br />';
  echo '<input name="nextmtgdate" type="text" size="30" value="'.$nextmtgdate.'" /><br /><br />';
  echo 'Next Meeting Time<br />';
  echo '<input name="nextmtgtime" type="text" size="30" value="'.$nextmtgtime.'" /><br /><br />';
  echo 'Next Meeting Place<br />';
  echo '<input name="nextmtgroom" type="text" size="30" value="'.$nextmtgroom.'" /><br /><br />';
  echo 'Chapter Description<br />';
  echo '<textarea name="chapterdescription" cols="60" rows="15" value="'.$chapterdescription.'"></textarea>';
  echo '</p>';
                      echo '<p>Chapter News<br />';
    echo '<textarea name="chapternews" cols="60" rows="15" value="'.$chapternews.'"></textarea>';
    echo '<br />';
    echo '<br />';
  echo 'Special Announcements<br />';
  echo '<input name="specials" type="text" size="30" value="'.$specials.'" />';
  echo '<br />';
  echo '<br />';
  echo 'Last Updated (Todays Date)<br />';
  echo '<input name="lastupdated" type="text" size="30" />';
  echo '<br />';
  echo '<br />';
  echo '<input type="submit" value="Update Chapter Page" />';
                      echo '</p>';
                      echo '<p>&nbsp; </p>';
    echo '</form>';

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29171-edit-information-page-issues/
Share on other sites

Try putting "mysql_close();"

ALL the way at the end.

I am not too sure of why you have it there o.o


Oh. You might want to add a thing to see if it's a real chapter..
$count = mysql_num_rows($result);

then..
if ($count == '0') {
echo "This chapter does exist.";
die();
}
else {
// stuff.
}
I meant where is the value coming from for the variable [b]$num[/b] in this code
[code]while ($i < $num) [/code]
usually I see people mysql_num_rows()  to figure out what $num is.

I personally perfer this method [b]while($row = mysql_fetch_array($result))[/b]

Here is an example.

[code] //connect to database
  mysql_select_db($database_dataConn, $dataConn);
 
  //create sql
  $sql_user_data="SELECT * FROM albums WHERE `id` ='$orig_id' LIMIT 1 ;";

  #print("$sql_user_data");
  // this statement actually executes the sql
  $result = mysql_query($sql_user_data);

  //access record info and build form
  while($row = mysql_fetch_array($result)) {

print ("$row[hits]");
}

}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.