joesaddigh Posted July 21, 2009 Share Posted July 21, 2009 Hi, I am trying to make the value of a text area equal the contents of a variable and it doesnt seem to work? echo '<textarea name="coursedescription" id="h" COLS=40 ROWS=6 value=">'.$coursedescription.'"</textarea>'; Any advice would be great Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/ Share on other sites More sharing options...
StefanRSA Posted July 21, 2009 Share Posted July 21, 2009 No need to set the value. Just use: echo '<textarea name="coursedescription" id="h" cols="40" rows="6">'.$coursedescription.'</textarea>'; It should work fine Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879834 Share on other sites More sharing options...
joesaddigh Posted July 21, 2009 Author Share Posted July 21, 2009 That works Thank you so much I don't spose you know if there is a way of getting the text that is in that variable to be read as text and ignore the fact that is html, if that makes sense the text in the variable is <table width="400" border="1" cellpadding="4" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111"> <tr bgcolor="#CCCCCC" class="bodygrey10"> <td width="100%" colspan="6"> <b>Example Timetable</b> </td> </tr> <tr bgcolor="#CCCCCC" class="bodygrey10"> <td width="15%"> </td> <td width="17%"><strong>Monday</strong></td> <td width="17%"><div align="left"><strong>Tuesday</strong></div></td> <td width="17%"><div align="left"><strong>Wednesday</strong></div></td> <td width="17%"><div align="left"><strong>Thursday</strong></div></td> <td width="17%"><div align="left"><strong>Friday</strong></div></td> </tr> <tr valign="top" bgcolor="#DDDDDD" class="bodygrey10"> <td>9.00- 10.30 </td> <td><strong>Grammar</strong>: Future tenses and uses of will</td> <td><div align="left"><strong>Listening:</strong> Scientific predictions</div></td> <td><div align="left"><strong>Authentic Texts:</strong> Newspapers and magazines</div></td> <td><div align="left"><strong>Reading and Listening:</strong> Environment</div></td> <td><div align="left"><strong>Grammar:</strong> New words in the media</div></td> </tr> <tr valign="top" bgcolor="#DDDDDD" class="bodygrey10"> <td>10.30- 10.45</td> <td>Break</td> <td>Break</td> <td>Break</td> <td>Break</td> <td>Break</td> </tr> <tr valign="top" bgcolor="#DDDDDD" class="bodygrey10"> <td>10.45- 12.00</td> <td><strong>Writing:</strong> Style and tone </td> <td><strong>Speaking: </strong>Presentations </td> <td><strong>Listening:</strong> Radio news and discussion</td> <td><strong>Speaking / Presentations:</strong> Reports</td> <td><strong>Writing:</strong> Review of past week’s grammar and lexis</td> </tr> <tr valign="top" bgcolor="#DDDDDD" class="bodygrey10"> <td>12.00- 13.00</td> <td>Lunch</td> <td>Lunch</td> <td>Lunch</td> <td>Lunch</td> <td>Lunch</td> </tr> <tr valign="top" bgcolor="#DDDDDD" class="bodygrey10"> <td>13.00- 15.00</td> <td><strong>Listening:</strong> Labelling a map<br> <strong>Reading:</strong> Locating information</td> <td> </td> <td><strong>Speaking:</strong> Interview Practice</td> <td> </td> <td> </td> </tr> </table> Which gets read into the box fine eventually. When it first gets read in It simply shows the table with an error message Warning: Cannot modify header information - headers already sent by (output started at E:\domains\c\cisukschool.co.uk\user\htdocs\test\Admin\editcoursesubmiteddetails.php:33) in E:\domains\c\cisukschool.co.uk\user\htdocs\test\Admin\editcoursesubmiteddetails.php on line 48 Then if you press back it will display the variable text in the text area as planned. Any ideas how to solve this so that it will not read it as html Thanks Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879841 Share on other sites More sharing options...
StefanRSA Posted July 21, 2009 Share Posted July 21, 2009 First things first... To get rid of the error put <? ob_start();?> on the top of your form and <? ob_flush(); ?> right at the bottom of your form. To display the variable on a form I would use: <div style="width: 300px; height: 150px; overflow: auto; padding: 5px"> <? echo $coursedescription ;?></div> Hope it helps??? Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879845 Share on other sites More sharing options...
joesaddigh Posted July 21, 2009 Author Share Posted July 21, 2009 Im not sure if I understand what you mean or what obstart and flush do... I have put it in various places, do you mean actually in the <form> syntax? echo '<form ob_start(); name="editcourse" id="editcourse" method="post" action="updatecourse.php" onsubmit="return validate_form()">'; echo'</form ob_flush();>'; I know this may seem really stupid. As for formatting the vairable with css, the variable will not always contain a table it could contain text etc... Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879852 Share on other sites More sharing options...
StefanRSA Posted July 21, 2009 Share Posted July 21, 2009 No, Put the <? ob_start();?> on its own at the begining of your page before you put anything else and the <? ob_flush(); ?> on its own at the bottom of your page as is. <div style="width: 300px; height: 150px; overflow: auto; padding: 5px"> <? echo $coursedescription ;?></div> is used just to display the variable in a text box Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879857 Share on other sites More sharing options...
joesaddigh Posted July 21, 2009 Author Share Posted July 21, 2009 Ok I have editted the code as you said and still dont have the desired results. The css code you gave me works fine but is not what i need. The reason being that it puts the table in the text box and not the code 'text' without executing it. Im sorry if I didnt explain myself very well. :-) The text area code that we discussed eariler works once getting the error that I posted previously and pressing back. My code at the moment is as follows for the wholepage. <?php ob_start(); session_start(); if (isset($_SESSION['user']) == false) { header("Location:adminlogin.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="../cis.css" rel="stylesheet" type="text/css" media="screen" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cisukschool.co.uk: Great value learning</title> <SCRIPT language=JavaScript> //Javascript function - Reload page when user selects course dropdown so that values can be repopulated function reload(form){ var val=form.CourseTitle.options[form.CourseTitle.options.selectedIndex].value; self.location='editcourseform.php?CourseTitle=' + val ; } </script> <script type="text/javascript"> var msg = ''; function validate_form() { valid = true; if(document.editcourse.coursetitle.value == '') { msg=msg+"Course Title cannot be left blank.\n"; valid = false; } if(document.editcourse.courseprice.value == '') { msg=msg+"Price cannot be left blank.\n"; valid = false; } if(document.editcourse.courselevel.value == '') { msg=msg+"Course Level cannot be left blank.\n"; valid = false; } if(document.editcourse.fee.value == '') { msg=msg+"Enrolment Fee cannot be left blank.\n"; valid = false; } if(document.editcourse.coursequalification.value == '') { msg=msg+"Qualification cannot be left blank.\n"; valid = false; } if(document.editcourse.coursedescription.value == '') { msg=msg+"Description cannot be left blank.\n"; valid = false; } if(msg=="" && valid ==true) { MM_popupMsg('Course Edit Successful!') register.submit(); } else { msg = "You have the following errors which must be corrected: \n" + msg; alert (msg); //Initialise variable msg = ''; } return valid; } //Display Message Registration complete function MM_popupMsg(msg) { alert(msg); } </script> </head> <!--Open body--> <body> <!--Open container--> <div id="container"> <!--Open header--> <div id="topheader"> <!--Open form, used to logout student--> <div id="formlogout"> <!--Form code--> <form name="logout" id="logout" method="get" action="../logout.php"> <label> <input type="submit" name="submit" value="Log out" tabindex="1" class="submitbutton" /> </label> <!--Close form code--> </form> <!--Close form--> </div> <h2> <?php echo $_SESSION['name'];?> logged in </h2> <!--Close header--> -</div> <!--Open logo--> <div id="logo"> <!--Close logo--> </div> <!--Open left column--> <div id="leftcolumn"> <h1> Welcome</h1> <?php include "admin_links.php"; ?> <!--Close left column--> </div> <div id="rightcolumn"> <?php if (isset($_SESSION['coursetitle'])) { $coursetitle = $_SESSION['coursetitle']; } else { $coursetitle = ""; } if (isset($_SESSION['courselevel'])) { $courselevel = $_SESSION['courselevel']; } else { $courselevel = ""; } //If there is a course level and title if($coursetitle!="" && $courselevel!="") { //Get session values, store in variables $courseprice = $_SESSION['courseprice']; $coursefee = $_SESSION['coursefee']; $coursequalification = $_SESSION['coursequalification']; $courseactive = $_SESSION['courseactive']; $coursedescription = $_SESSION['coursedescription']; //Create form with course details echo '<form name="editcourse" id="editcourse" method="post" action="updatecourse.php" onsubmit="return validate_form()">'; echo '<label>Edit course'; echo '<hr />'; echo '<br />'; echo '</label>'; echo '<label> Course name:'; echo '<input type="text" name="coursetitle" value = "'.$coursetitle.'" tabindex="" />'; echo ' *'; echo'<br />'; echo'<br />'; echo'</label>'; echo '<label> Course level:'; echo '<input type="text" name="courselevel" value = "'.$courselevel.'" tabindex="" />'; echo ' *'; echo'<br />'; echo'<br />'; echo'</label>'; echo '<label> Course price:'; echo '<input type="text" name="courseprice" value = "'.$courseprice.'" tabindex="" />'; echo ' *'; echo'<br />'; echo'<br />'; echo'</label>'; echo '<label> Course enrolment fee:'; echo '<input type="text" name="coursefee" value = "'.$coursefee.'" tabindex="" />'; echo ' *'; echo'<br />'; echo'<br />'; echo'</label>'; echo '<label> Course qualification:'; echo '<input type="text" name="coursequalification" value = "'.$coursequalification.'" tabindex="" />'; echo ' *'; echo'<br />'; echo'<br />'; echo'</label>'; echo '<label> Course active:'; echo '<input type="text" name="courseactive" value = "'.$courseactive.'" tabindex="" />'; echo'<br />'; echo'<br />'; echo'</label>'; echo '<label> Course description:'; echo ' *'; echo'<br />'; echo'<br />'; //echo '<input type="text" id = "h" name="coursedescription" value = "'.$coursedescription.'" tabindex="" />'; echo '<textarea name="coursedescription" id="h" cols="40" rows="6">'.$coursedescription.'</textarea>'; //echo '<div style="width: 300px; height: 150px; overflow: auto; padding: 5px">'; //echo $coursedescription; //echo '</div>'; echo'<br />'; echo'<br />'; echo'</label>'; echo'<label>'; echo'<input type="submit" name="submit" value="submit" tabindex="2" class="submitbutton" />'; echo'</label>'; echo'</form>'; } //If there is no coursetitle or level else { echo '<form name="editcourse" id="editcourse" method="post" action="editcoursesubmiteddetails.php">'; echo '<label>Edit course'; echo '<hr />'; echo '<br />'; echo '</label>'; echo '<label> Course name:'; include("../coursenameselectionenrolmentform.php"); echo '<br />'; echo '<br />'; echo '</label>'; echo '<label>'; echo '<input type="submit" name="submit" value="submit" tabindex="2" class="submitbutton" />'; echo '</label>'; echo '</form>'; } ?> <!--Close right column--> </div> <!--Open footer--> <div id="footer"> <p align="center"> CIS School of English ADMIN</p> <!--Close footer--> </div> <!--Close the container--> </div> <!--Close body--> </body> </html> <?php ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879860 Share on other sites More sharing options...
StefanRSA Posted July 21, 2009 Share Posted July 21, 2009 Is the form you posted the editcoursesubmiteddetails.php? Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879868 Share on other sites More sharing options...
joesaddigh Posted July 21, 2009 Author Share Posted July 21, 2009 No The way that it works is a form gets posted and then runs this script which basically populates vairbales based on the chosen course title and level which is the script that the error is complaing about <?php session_start(); //Admin privileges require "../connectadmin.php"; //Get the course details which are unique together if (isset($_POST['CourseTitle'])) { $coursetitle=$_POST['CourseTitle']; } if (isset($_POST['CourseLevel'])) { $courselevel=$_POST['CourseLevel']; } //Set the query $queryeditcourse = "select * from course WHERE CourseTitle = '".$coursetitle."' AND CourseLevel = '".$courselevel."'"; $resultcourse = mysql_query($queryeditcourse) or die("Error getting course details"); $rowcourse = mysql_fetch_array($resultcourse); //Store values in the session echo $_SESSION['coursetitle'] = $coursetitle; echo $_SESSION['courselevel'] = $courselevel; echo $_SESSION['courseprice'] = $rowcourse['CoursePrice']; echo $_SESSION['coursefee'] = $rowcourse['CourseEnrolmentFee']; echo $_SESSION['coursequalification'] = $rowcourse['CourseQualification']; echo $_SESSION['courseactive'] = $rowcourse['CourseActive']; echo $_SESSION['coursedescription'] = $rowcourse['CourseDescription']; //Get the course id, perform seperate query, Save id in session variable $queryeditcourse = "select CourseId from course WHERE CourseTitle = '".$coursetitle."' AND CourseLevel = '".$courselevel."'"; $resultcourse = mysql_query($queryeditcourse) or die("Error getting course details"); $rowcourse = mysql_fetch_assoc($resultcourse); $courseid = $rowcourse['CourseId']; $_SESSION['courseid'] = $courseid; //Return user to course page header("Location: editcourseform.php"); exit(); ?> It seems to be complaining about the header("Location..............) bit of code?? Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879873 Share on other sites More sharing options...
joesaddigh Posted July 21, 2009 Author Share Posted July 21, 2009 Right sorted I needed to put the start/flush code on that script# Thank you so much all working perfectly!! Sorry for being so clueless! Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879879 Share on other sites More sharing options...
StefanRSA Posted July 21, 2009 Share Posted July 21, 2009 no problem m8t! I sat with the same problems just the other day Quote Link to comment https://forums.phpfreaks.com/topic/166859-solved-simple-text-area-value-using-a-variable/#findComment-879885 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.