Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a textarea to modify a MySQL table field
    primarykey
    data
    text
    <p>Basically I want a user to be able to create a list that looks something like this:</p> <pre><code>Please give me all books by: James Arnold Tom Seaver </code></pre> <p>I only need line breaks preserved...</p> <p>My code is giving me a problem: When I save the information into the database, the formatting is being preserved, but when I put the information into the textarea, there are a lot of extra spaces. I have attached a picture so you can see what it looks like.</p> <pre><code>&lt;?php session_start(); if (!isset($_SESSION['user'])) header('Location: ../index.php'); require ("../login.php"); include ("header.php"); include ("subnav.php"); $user_id = $_SESSION['user']; $form_show = true; if (isset($_POST['submit'])) { if (empty($_POST['notes'])) { $stmt = $db-&gt;prepare("SELECT * FROM notes WHERE user=:id"); $stmt-&gt;bindValue(':id', $user_id, PDO::PARAM_INT); $stmt-&gt;execute(); $rows = $stmt-&gt;fetchAll(); $num_rows = count($rows); if ($num_rows == 0) { $form_show = false; $errors[] = 'You do not currently have any notes to edit, therefore nothing to delete!.'; } else { $stmt = $db-&gt;prepare("DELETE FROM notes WHERE user=:id"); $stmt-&gt;bindValue(':id', $user_id, PDO::PARAM_INT); $stmt-&gt;execute(); $errors[] = 'Your notes have been successfully deleted.'; $form_show = false; } } else { $stmt = $db-&gt;prepare("SELECT * FROM notes WHERE user=:id"); $stmt-&gt;bindValue(':id', $user_id, PDO::PARAM_INT); $stmt-&gt;execute(); $rows = $stmt-&gt;fetchAll(); $num_rows = count($rows); if ($num_rows == 0) { $stmt = $db-&gt;prepare("INSERT INTO notes (user, notes) VALUES (:user, :notes)"); $stmt-&gt;bindValue(':user', $user_id, PDO::PARAM_INT); $stmt-&gt;bindValue(':notes', trim($_POST['notes']), PDO::PARAM_STR); $stmt-&gt;execute(); echo 'Your notes have been successfully added!'; $form_show = false; } else { $stmt = $db-&gt;prepare("UPDATE notes SET notes=:notes WHERE user=:id"); $stmt-&gt;bindValue(':notes',trim($_POST['notes']), PDO::PARAM_STR); $stmt-&gt;bindValue(':id', $user_id, PDO::PARAM_INT); $stmt-&gt;execute(); echo 'Your notes have been successfully updated!'; $form_show = false; } } } ?&gt; &lt;?php if (!empty($errors)) foreach($errors as $error) echo $error; ?&gt; &lt;?php if ($form_show == true) { ?&gt; &lt;p&gt;Use this page to add any notes you would like to list for your subscription. For example, if you want all books by a particular artist, here is the place to add that information!&lt;/p&gt; &lt;form action="" method="post"&gt; &lt;ul&gt; &lt;li&gt; Notes: &lt;br&gt; &lt;textarea name="notes" rows="30" cols="70"&gt; &lt;?php $stmt = $db-&gt;prepare("SELECT * FROM notes WHERE user=:id"); $stmt-&gt;bindValue(':id', $user_id, PDO::PARAM_INT); $stmt-&gt;execute(); $rows = $stmt-&gt;fetchAll(); $num_rows = count($rows); if ($num_rows != 0) foreach ($rows as $row) echo $row['notes']; ?&gt; &lt;/textarea&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="submit" value="Modify Notes" name ="submit" id="submit"&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; &lt;?php } ?&gt; &lt;?php include ("footer.php"); ?&gt; </code></pre> <p>Here is a picture:</p> <p><img src="https://i.stack.imgur.com/rl7F5.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload