jlev89 Posted December 1, 2006 Share Posted December 1, 2006 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> </p>'; echo '</form>'; ?>[/code] Quote Link to comment Share on other sites More sharing options...
jsladek Posted December 1, 2006 Share Posted December 1, 2006 where is $num coming from?while ($i < $num) {-John Quote Link to comment Share on other sites More sharing options...
jlev89 Posted December 1, 2006 Author Share Posted December 1, 2006 Not sure why I need it in there...but I removed it then got a parse error when I tried to view the page.-Jordan Quote Link to comment Share on other sites More sharing options...
ataria Posted December 1, 2006 Share Posted December 1, 2006 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.} Quote Link to comment Share on other sites More sharing options...
jlev89 Posted December 1, 2006 Author Share Posted December 1, 2006 No... none of those things seemed to work. Is the format I am calling the variables in the "value" arguments in the form code correct?[code]echo '<input name="chapter" type="text" size="30" value="'.$chapter.'"> <br /><br />';[/code]Jordan Quote Link to comment Share on other sites More sharing options...
jsladek Posted December 2, 2006 Share Posted December 2, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.