Murciano Posted March 9, 2010 Share Posted March 9, 2010 I think im declaring this variable correctly "editor1" , yet every time i run the script i get an error Undefined variable: editor1 in <b>C:\wamp\www\simplycms\create_new_listing.php . This bit of script is to pull a title from a dropdown selection and then when submitted (by clicking) further information from a MySQL field named "editor1" is then sent to the textarea (line 59) where it is echoe'd <?php if (isset($_POST['submit'])) { // lets retrieve the posted rowID $rowID = $_POST['rowID']; // Now select the template content that is associated with the rowID $q = ("SELECT editor1 FROM templates WHERE editor1='$rowID'"); // Assign the template information into a variable list($editor1) = mysql_fetch_row($result);<!-- ##### this is where the variable is assigned (i think) ##### --> } ?> <div id="editor_wrapper"> <div id="editor"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Location: <input type="text" name="location" size="40"> Company Name: <input type="text" name="company_name" size="40"></p> <input type="hidden" name="rowID" value="<?php echo $rowID; ?>"> <textarea name="editor1"><?php echo $editor1; ?></textarea><!-- ###### this is line 59 ##### --> <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); </script> </p> <p> <input type="submit" name="submit" /> </p> </form> anybody have any insights for a php newbie..thanks Quote Link to comment https://forums.phpfreaks.com/topic/194668-undefined-variable-problem-to-populate-text-area/ Share on other sites More sharing options...
taquitosensei Posted March 9, 2010 Share Posted March 9, 2010 This should do it <textarea name="editor1"><?php echo (isset($editor1))?$editor1:""; ?></textarea> Quote Link to comment https://forums.phpfreaks.com/topic/194668-undefined-variable-problem-to-populate-text-area/#findComment-1023772 Share on other sites More sharing options...
Murciano Posted March 9, 2010 Author Share Posted March 9, 2010 Thanks, thats nailed the variable error but the text area isnt populating with the data from the db field, still its a lot closer than it was an hour or so ago, just have to keep on plugging away at things Quote Link to comment https://forums.phpfreaks.com/topic/194668-undefined-variable-problem-to-populate-text-area/#findComment-1023778 Share on other sites More sharing options...
Murciano Posted March 9, 2010 Author Share Posted March 9, 2010 Just been trying a bit more on this and getting nowhere, what i have found though is when i unhide this hidden field for rowID <input type="hidden" name="rowID" value="<?php echo $rowID ?>" this also throws an undefined variable error, when i apply the fix from taquitosensei and adapt it for rowID <input type="hidden" name="rowID" value="<?php echo (isset($rowID))?$rowID:""; ?>"> then it pulls in the titles that are in the dropdown selector should this not be showing the numerical value of the rowID as it is an INT with auto increment.. Quote Link to comment https://forums.phpfreaks.com/topic/194668-undefined-variable-problem-to-populate-text-area/#findComment-1023826 Share on other sites More sharing options...
Murciano Posted March 10, 2010 Author Share Posted March 10, 2010 Hmmm this is the whole block of code that should get the variable and then populate the textfield, i've been at it for hours now and nothing will show in the <textarea> when the variable for editor1 is called. <?php if (isset($_POST['submit'])) { // lets retrieve the posted rowID $rowID = $_POST['rowID']; // Now select the template content that is associated with the rowID $q = ("SELECT editor1 FROM templates WHERE rowID='$rowID'"); // Assign the template information into a variable list($editor1) = mysql_fetch_row($q) or die("A MySQL error has occurred.<br />Your Query: (" . mysql_errno() . ") " . mysql_error()); echo '<div id="editor_wrapper">'; echo '<div id="editor">'; } ?> <!-- ##### THIS FORM SHOWS (should show) THE INFORATION FROM EDITOR1 FIELD IN db ##### --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Location: <input type="text" name="location" size="40"> Company Name: <input type="text" name="company_name" size="40"></p> <input type="hidden" name="rowID" value="<?php echo (isset($rowID))?$rowID:""; ?>"> <textarea name="editor1"><?php echo (isset($editor1))?$editor1:""; ?></textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); </script> </p> <p> <input type="submit" name="submit" /> </p> </form> when i echo rowID in the textarea it shows the title which is in the dropdown selector (assigned "name") in MySQl, this table only has 3 fields rowID (INT) name (VAR) editor1(TEXT) so why is rowID populating by using whats in the "name" field and why is the "editor1" not being echoed in the textarea (or elsewhere as i have done test echo's to see if it will echo anywhere else.. Quote Link to comment https://forums.phpfreaks.com/topic/194668-undefined-variable-problem-to-populate-text-area/#findComment-1024146 Share on other sites More sharing options...
Murciano Posted March 12, 2010 Author Share Posted March 12, 2010 Im still stuck with this, im getting no errors on the page yet the echo for "editor1" based on "id" just is not happening, any pointers on where i am going wrong would be higjly appreciated.. <?php include("header.php"); ?> <div class="dropdown"> <p> <!-- ##### CREATE THE DROPDOWN SELECTION ##### --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php function create_dropdown($identifier,$pairs,$firstentry) { $dropdown ="<select name=\"$identifier\">"; $dropdown .= "<option name=\"Fetch Template\">$firstentry</option>"; foreach($pairs AS $value => $name) { $dropdown .="<option name=\"$value\">$name</option>"; } echo "</select>"; return $dropdown; } // Lets gather the data from the templates table $q = ("SELECT id, name FROM templates ORDER BY name"); $result = mysql_query($q); // Now its time to build an array based on the templates table data while($row = mysql_fetch_array($result)) { $value = $row["id"]; $name = $row["name"]; $pairs["$value"] = $name; } echo create_dropdown("id",$pairs,"Choose A Template"); ?> <input type="submit" name="submit" value="Fetch Template" /> </form> </p> </div> <!-- ##### END THE DROPDOWN ##### --> <!-- ##### BEGIN GETTING THE INFORMATION FROM THE SUBMITTED DROPDOWN DATA ##### --> <?php //$conn = mysql_connect("localhost", "root", "") or die ("can not connect"); //mysql_select_db("simplycms") or die ("cant find database"); // If the form has been submitted then: if (isset($_GET['submit'])) { // Get the posted id $id = $_GET['id']; // Select the data that corresponds to the selected id $q = ("SELECT editor1 FROM templates WHERE id='$id'") or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); $result = mysql_query($q)or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); // Assign the template information to a variable list($editor1) = mysql_fetch_row($result); } ?> <!-- ##### THIS FORM SHOWS (or should show) THE INFORMATION FROM EDITOR1 FIELD IN db ##### --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="test" method="post"> <p>Location: <input type="text" name="location" size="40" /> Company Name: <input type="text" name="company_name" size="40" /></p> <input type="text" name="id" value="<?php echo (isset($id))?$id:""; ?>"> <textarea name="editor1"><?php echo (isset($editor1))?$editor1:""; ?></textarea> // <-- THIS IS THE AREA I WANT THE ECHO TO SHOW <script type="text/javascript"> CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl : 'ckfinder/ckfinder.html', filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?type=Images', filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?type=Flash', filebrowserUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' } ); </script> </p> <p> <input type="submit" name="submit" /> </p> </form> <!-- ##### END OF RETRIEVED FIELD DATA ##### --> <!-- ##### UPDATED TEMPLATES ARE THEN INSERTED ON SUBMIT TO "LISTINGS" TABLE IN db ##### --> <?php // this part updates the database with the newly created business listing if (isset($_POST['submit'])) { $id = $_POST['id']; $location = $_POST['location']; $company_name = $_POST['company_name']; $editor1 = $_POST['editor1']; // lets populate the database with this new information $q = ("INSERT INTO listings SET location='$location', company_name='$company_name', editor1='$editor1'"); $result = mysql_query($q); // success or failure ? if ($result) echo "<p>The new listing was successfully inserted into the database</p>"; else echo "<p>There was a problem, the data got lost on the way.</p>"; } ?> <!-- ##### END OF EDITING AND SENDING THE EDITED TO THE "LISTINGS" db TABLE ##### --> </div><!-- /editor --> </div><!-- /editor_wrapper --> <!-- START OF FOOTER --> </div><!-- /wrapper --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/194668-undefined-variable-problem-to-populate-text-area/#findComment-1025292 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.