Hello everyone,

I have the following script:


// Check connection
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
$resultaat = mysqli_query($con, "SELECT `question` FROM databasename WHERE `id`= 2");
    while ($row = mysqli_fetch_assoc($resultaat))
     echo '<table>';
     echo '<tr>';
     echo '<td>'. '<input type="text"  value= '.$row['question'] . ' </td>';
     echo '<td>' . "<input type='submit' value='Update'>" . '</td>'; 
     echo '</tr>';
     echo '</table>';

Now what the problem is, is that only the first word is show. While the row[question] more than 1 word.
Tried and googled..


Put quotes around the value and close your input tag in line 15:

echo '<td>'. '<input type="text"  value= "'.$row['question'] . '"/> </td>';
Member Avatar

As bnmng says, but don't know why you're spitting out echoes all over the place. Easier to show a block of html as html:

 while ($row = mysqli_fetch_assoc($resultaat))
         <td><input type="text"  value="<?= $row['question'] ?>" /></td>
         <td><input type="submit" value="Update" /></td>

However, you seem to have multiple tables and identical submits and no form tags nor names for your inputs. Are we to assume that you are using javascript to ajax these updates just using tag selectors as hooks, e.g. jQuery version of parents() and find()?
If not, I can't see how the server is going to get any data. Do you really need a new table for every record? Or would shifting the while loop to inside the table tags be better, so that you're just creating new rows?