0

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

3
Contributors
2
Replies
11
Views
2 Years
Discussion Span
Last Post by diafol
0

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

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

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?

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.