captain_scarlet87 Posted April 16, 2010 Share Posted April 16, 2010 Hi, I need the submitted textarea called instructions to record all the blank spaces that are within the box. For example I have submitted some data such as this: 1. Do this. 2. Do that. There is a space between them however when I display the contents it comes up as: 1. Do this. 2. Do that. So basically I need exactly the same formating to be displayed as to what has been submitted in the form. Please help me. Thanks. Code submitting the form: <?php # Script 13.6 - upload_instructions.php // Include the configuration file for error management and such. require_once ('./includes/config.inc.php'); // Set the page title and include the HTML header. $page_title = 'Upload Instructions'; include ('./includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once ('../mysql_connect.php'); // Connect to the database. $topic = $_POST['topic']; // Check for a title. if (eregi ('^[[:alpha:]\.\' \-]{2,50}$', stripslashes(trim($_POST['title'])))) { $t = escape_data($_POST['title']); } else { $t = FALSE; echo '<p><font color="red" size="+1">Please enter your title.</font></p>'; } // Check for a instructions. if (strlen (stripslashes(trim($_POST['instructions'])))) { $i = escape_data($_POST['instructions']); } else { $i = FALSE; echo '<p><font color="red" size="+1">Please enter your instructions.</font></p>'; } if ($t && $i) { // If everything's OK. // Add the user. $query = "INSERT INTO uploaded_instructions (title, topic, instructions) VALUES ('$t', '$topic', '$i' )"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. // Finish the page. echo '<h3>Instructions submission successful!</h3>'; include ('./includes/footer.html'); // Include the HTML footer. exit(); } else { // If it did not run OK. echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>'; } } else { // If one of the data tests failed. echo '<p><font color="red" size="+1">Please try again.</font></p>'; } mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <h1>Upload Instructions</h1> <form action="upload_instructions.php" method="post"> <fieldset> <p><b>Title:</b> <input type="text" name="title" size="100" maxlength="100" value="<?php if (isset($_POST['topic'])) echo $_POST['title']; ?>" /></p> <p><b>Topic:</b> <select name="topic"><option value="crm">CRM</option><option value="email">Email</option><option value="internet">Internet</option><option value"other">Other</option><p></select> <p><b>Instructions:</b><br><textarea name="instructions" maxlength="1000" rows="30" cols="120" value="<?php if (isset($_POST['instructions'])) echo $_POST['instructions']; ?>" /></textarea> </p> <div align="center"><input type="submit" name="submit" value="Upload Instructions" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('./includes/footer.html'); ?> Code to display the submitted data: <?php # Script 13.8 - view_instructions.php // Include the configuration file for error management and such. require_once ('./includes/config.inc.php'); // Set the page title and include the HTML header. $page_title = 'View Instructions'; include ('./includes/header.html'); $instructions_id = $_GET['instructions_id']; ?> <h1>View Instructions:</h1> <fieldset> <table> <tr> <td> <table> <?php require_once ('../mysql_connect.php'); // Connect to the database. $order = "SELECT * FROM uploaded_instructions WHERE instructions_id=$instructions_id"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ echo ("<tr><td><b>$row[title]</b></td>"); echo ("<tr><td></td>"); echo ("<tr><td>$row[instructions]</td>"); } ?> </table> </td> </tr> </table> </fieldset> <?php include ('./includes/footer.html'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/198760-recording-and-displaying-blank-space-from-submitted-form/ Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 What does the function escape_data do? Quote Link to comment https://forums.phpfreaks.com/topic/198760-recording-and-displaying-blank-space-from-submitted-form/#findComment-1043140 Share on other sites More sharing options...
ChemicalBliss Posted April 16, 2010 Share Posted April 16, 2010 IT is because the Form submits Newlines, whereas you are viewing it in HTML rather than Plain Text. So, Use nl2br() to convert Plain Text Newlines into HTML <BR> Tags. echo ("<tr><td>".nl2br($row[instructions])."</td>"); -cb- Quote Link to comment https://forums.phpfreaks.com/topic/198760-recording-and-displaying-blank-space-from-submitted-form/#findComment-1043141 Share on other sites More sharing options...
captain_scarlet87 Posted April 16, 2010 Author Share Posted April 16, 2010 IT is because the Form submits Newlines, whereas you are viewing it in HTML rather than Plain Text. So, Use nl2br() to convert Plain Text Newlines into HTML <BR> Tags. echo ("<tr><td>".nl2br($row[instructions])."</td>"); -cb- Tried this but this error came up: An error occurred in script 'C:\wamp\www\html\view_instructions.php' on line 26: Use of undefined constant instructions - assumed 'instructions' Any further ideas? Quote Link to comment https://forums.phpfreaks.com/topic/198760-recording-and-displaying-blank-space-from-submitted-form/#findComment-1043145 Share on other sites More sharing options...
ChemicalBliss Posted April 16, 2010 Share Posted April 16, 2010 I should of done it in my code but; You need to encapsulate each key your using in single quotes: 'instructions' 'title' etc.. -cb- Quote Link to comment https://forums.phpfreaks.com/topic/198760-recording-and-displaying-blank-space-from-submitted-form/#findComment-1043146 Share on other sites More sharing options...
captain_scarlet87 Posted April 16, 2010 Author Share Posted April 16, 2010 Thanks cb, it worked! Quote Link to comment https://forums.phpfreaks.com/topic/198760-recording-and-displaying-blank-space-from-submitted-form/#findComment-1043161 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.