Hello everyone,

I have the following script:

<?php


$con=mysqli_connect("localhost","name","name","database");
// 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..

Thanks
Reminem

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

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

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))
 {
 ?>
 <table>
     <tr>
         <td><input type="text"  value="<?= $row['question'] ?>" /></td>
         <td><input type="submit" value="Update" /></td>
     </tr>
 </table>
<?php
}

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.