This is my code to display code out of my database:
<?php
while($row = mysqli_fetch_array($myData)){
echo '<form action="details.php?ID='.$row['ID'].'" method="post">';
echo '<tr>';
echo '<input type="hidden" name="ID" value="'.$row['ID'].'">';
echo '<td>' . $row['ID'] . '</td>';
echo '<td>' . '<input name="title" value="' . $row['Title'] . '">' .'</td>' ;
echo '<td>' . '<input size=85 name="detail" value="' . $row['Detail'] . '" cols="85" rows="2">'.'</td>';
echo '<td>' . $row['eventDate'] . '</td>';
echo '<td>' . $row['dateAdded'] . '</td>';
echo '<td>' . '<input type="submit" name="update" value="update" class="btn btn-default"> ' . '</td>';
echo '<td>' . '<input type="submit" name="delete" value="delete" class="btn btn-default"> ' . '</td>';
echo '</tr>';
echo '</form>';
}
?>
When I try to change the Inputs to <textarea>'s it stops showing the data from the database but only the text field. When I check Page Source it shows the data. How to format the fields like this:
echo '<td>' . '<textarea name="title" value="' . $row['Title'] . '">'. '</textarea>' .'</td>' ;
echo '<td>' . '<textarea size=85 name="detail" value="' . $row['Detail'] . '" cols="85" rows="2">'. '</textarea>' .'</td>';
textareas don't have a value attribute. Place the value between the opening and closing tags instead:
echo '<td><textarea name="title">'. $row['Title'] . '</textarea></td>' ;
echo '<td><textarea size=85 name="detail" cols="85" rows="2">'. $row['Detail'] .'</textarea></td>';
Try to insert the text between textarea tags instead of adding value attribute
echo '<td>' . '<textarea name="title">'. $row['Title'] .'</textarea>' .'</td>' ;
The general format for a text are field is <textarea name="name" cols="width" rows="height" wrap="type"> </textarea>
So there shouldn't be a value attribute. Something like this:
echo '<td>' . '<textarea name="title">'. '</textarea>' .'</td>' ;
Related
I am trying to make a table where data from a database is shown and by pressing on the update button the (not the 'lidnummer one')cells on the row should change to a form input field with the data from that row as the initial input values.
I've copied the idea from something I found and changed it to fit all the data I want to show, but I can't get the row to change upon pressing the 'update' button.
echo '<tr>';
echo '<td>Lidnummer</td>';
echo '<td>Voornaam</td>';
echo '<td>Achternaam</td>';
echo '<td>Huisnummer</td>';
echo '<td>Adres</td>';
echo '<td>E-mailadres(sen)</td>';
echo '<td>Telefoonnummer(s)</td>';
echo '<td>Update</td>';
echo '<td>Delete</td>';
echo '<tr>';
for ($j = 0 ; $j < $num_members ; ++$j)
{
$row = $select_result->fetch_array(MYSQLI_ASSOC);
echo '<tr>';
if(isset($_GET['lidnummer']) && $row['lidnummer'] == $_GET['lidnummer'])
{
echo '<form action="includes/update_ledenlijst.php" method="POST">';
echo '<td>' . $row["lidnummer"] . '</td>';
echo '<td><input type="text" name="voornaam" value="' . $row['voornaam'] . '"></td>';
echo '<td><input type="text" name="naam" value="' . $row['naam'] . '"></td>';
echo '<td><input type="text" name="huisnummer" value="' . $row['huisnummer'] . '"></td>';
echo '<td><select id="adres" name="adres">';
include 'includes/select_postcodes.php';
echo '</select>';
echo "<td>";
echo '<textarea>';
toon_contactgegevens("telefoonnummers", $row, $conn, "telefoonnummer", "form_data");
echo '</textarea>';
echo '</td>';
echo '<td>';
echo '<textarea>';
toon_contactgegevens('emails', $row, $conn, 'email', 'form_data');
echo '</textarea>';
echo '</td>';
echo '<td><button type="submit" class="buttons">Save</button></td>';
echo '<td>----</td>';
echo '</form>';
} else {
echo '<td>' . htmlspecialchars($row["lidnummer"]) . "</td>";
echo '<td>' . htmlspecialchars($row["voornaam"]) . "</td>";
echo '<td>' . htmlspecialchars($row["naam"]) . "</td>";
echo '<td>' . htmlspecialchars($row["huisnummer"]) . "</td>";
echo '<td>' . htmlspecialchars($row["adres"]) . ", " . htmlspecialchars($row["postcode"]) . " " . htmlspecialchars($row["woonplaats"]) . '</td>';
echo '<td>';
toon_contactgegevens('emails', $row, $conn, 'email', "table_data");
echo '</td>';
echo '<td>';
toon_contactgegevens("telefoonnummers", $row, $conn, "telefoonnummer", "table_data");
echo '</td>';
echo '<td><a class="buttons" href="home_ledenlijst.php?id='. $row["lidnummer"] . '" role="button">Update</a></td>';
}
echo "<td><a class='buttons' href='includes/delete_ledenlijst.php?id='" . $row['lidnummer'] . "' role='button'>Delete</a></td>";
echo "</tr>";
}
This will probably be something I have overlooked and is really easy.. But I am new to this so I am still learning :)
You're passing a value called id to the server:
href="home_ledenlijst.php?id='. $row["lidnummer"] . '"
But looking for a value called lidnummer:
$_GET['lidnummer']
How you identify the values needs to be the same. Try looking for the id value:
$_GET['id']
You are checking for $_GET['lidnummer'] but you are setting id='. $row["lidnummer"]
Change
id='. $row["lidnummer"]
to
lidnummer='. $row["lidnummer"]
Cheers! :)
=C=
I am trying to set the value of my checkbox. I do have a SQLite database with a table with some rows. Some rows contain STATUS = 1, some contain STATUS = 0.
... "STATUS" BOOL NOT NULL DEFAULT 1, ...
So I check the current row with the fetchArray function and everything else works fine, but in my HTML site, all checkboxes are checked. Is there a logical mistake?
while ($row = $table->fetchArray(SQLITE3_ASSOC))
{
$output .= '<tr>';
if ($row['STATUS'] == 1) {
$output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS" checked="true"></td>';
}
else {
$output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS" checked="false"></td>';
}
$output .= '<td class="USER" data-id2="' . $row['ID'] . '" contenteditable="true">' . $row['USER'] . '</td>
...
<td class="DESCRIPTION" data-id11="' . $row['ID'] . '" contenteditable="true">' . $row['DESCRIPTION'] . '</td>
<td><button type="button" name="btn_edit" data-id12="' . $row['ID'] . '" class="btn btn-xs btn-warning btn-block btn_edit">Edit</button></td>
<td><button type="button" name="btn_delete" data-id13="' . $row['ID'] . '" class="btn btn-xs btn-danger btn-block btn_delete">Delete</button></td>
</tr>';
}
This is the solution:
if ($row['STATUS'] == 1) {
$output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS" checked>' . $row['STATUS'] . '</td>';
}
else {
$output .= '<td class="STATUS" data-id1="' . $row['ID'] . '" bgcolor="#cecece"><input type="checkbox" name="STATUS">' . $row['STATUS'] . '</td>';
}
As you can see, I just changed the syntax of the HTML code. I don't know why the checked property has to be used like this, but to be honest I don't really care. ;-)
Hello guys I have a code that selects out of my database and puts it into the textbox. Yet it only shows 1 word instead of the whole sentence.
this is my code:
while($row = mysql_fetch_array($myData)){
echo '<form action="details.php?ID='.$row['ID'].'" method="post">';
echo "<tr>";
echo '<input type="hidden" name="ID" value="'.$row['ID'].'">';
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . "<input type=text name=title value=" . $row['Title'] . " </td>";
echo "<td>" . "<input type=text size=45 name=detail value=" . $row['Detail'] . " </td>";
echo "<td>" . $row['eventDate'] . "</td>";
echo "<td>" . $row['dateAdded'] . "</td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
I hope someone knows the answer because i've been stuck for like 1 hour and can't seem to find the answer. Thanks everyone!
you forget to close input all inputs should be closed properly.
echo '<td>' . '<input type="text" name="title" value="' . $row['Title'] . '">'.'</td>';
Also
echo '<td>' . $row['ID'] . '</td>';
echo '<td>' . '<input type="text" size="45" name="detail" value="'.$row['Detail'].'"></td>';
echo '<td>' . $row['eventDate'] . '</td>';
echo '<td>' . $row['dateAdded'] . '</td>';
echo '<td>' . '<input type="submit" name="update" value="update"> ' . '</td>';
echo '<td>' . '<input type="submit" name="delete" value="delete"> ' . '</td>';
I have following problem, I have list of products in a database and want to display them in table unfortunately it plays some tricks for me because it displays one td before table even begins.
Here are the PHP functions:
<?php
function displayProduct($code,$url)
{
echo '<form method="post" action="cart_update.php"><input type="hidden" name="code" value="' . $code . '"/>';
echo '<input type="hidden" name="return_url" value="' . $url . '" />';
echo '<input type="hidden" name="type" value="add" /><input type="submit" value="Add" /></form>';
}
function displayItem($obj,$url)
{
echo '<tr>';
echo '<td>' . $obj->menuposition . '</td><td>' . $obj->name . '</td><td>' . '£'.$obj->price . '</td><td>' . displayProduct($obj->code,$url) .'</td>';
echo '</tr>';
if(strlen($obj->description) > 2)
{
echo '<tr><td colspan="4" style="font-size: 10px;">' . $obj->description . '</td></tr>';
}
}
?>
And here is the HTML output that I get:
Could someone help me ?
The echo call from displayProduct happens before the echo call of displayItem occurs.
I can see two solutions.
1: displayProduct should return the things to write and not echo them.
2:
echo '<td>' . $obj->menuposition . '</td><td>' . $obj->name . '</td><td>' . '£'.$obj->price . '</td><td>';
displayProduct($obj->code,$url);
echo '</td>';
displayProduct($code,$url) should return the string instead of printing it out:
function displayProduct($code,$url)
{
$result = '<form method="post" action="cart_update.php"><input type="hidden" name="code" value="' . $code . '"/>';
$result .='<input type="hidden" name="return_url" value="' . $url . '" />';
$result .='<input type="hidden" name="type" value="add" /><input type="submit" value="Add" /></form>';
return $result
}
[Edit] I should read better the questions...
But this still applies:
Also as Adrian stated, you should not echo the lines in "displayProducts", but return a string.
Got stuck trying to echo out multiple rows with data based on checkbox input. As of current code it processes data from only one checkbox, no matter how many checkboxes are ticked. Please help!
while ($row = mysql_fetch_assoc($r)) {
$pals .= '<input type="checkbox" name="pal_num[]" value="'
. $row['pal_num'] . '">' . $row['pal_num'] . '<br>';
}
if ($pal == '') {
echo '';
} else {
echo '<form name="get_pal" action="post2.php" method="POST">';
echo $pals;
echo '<input type="submit" name="post" value="Go!">';
echo '</form>';
}
post2.php:
$w = $_POST['pal_num'];
$rrr = mysql_query("SELECT * FROM pl_tab WHERE pal_num" . $w[0]);
while ($row = mysql_fetch_array($rrr)) {
echo '<tr><td>' . ' ' . '</td>';
echo '<td rowspan="5">' . $row['descr'] . '</td>';
echo '<td><b>' . 'Total weight' . '<b></td>';
echo '<td>' . ' ' . '</td><td>' . ' ' . '</td></tr>';
echo '<td>' . ' ' . '</td>';
echo '<td colspan="3">' . ' ' . '</td>';
//this part should multiple based on how many checkboxes are ticked.
echo '<tr><td>' . $row['l_num'] . '</td>';
echo '<td>' . $row['pal_num'] . '</td>';
echo '<td>' . $row['weight 1'] . '</td><td>' . $row['weight 2'] . '</td></tr>';
}
echo "</table>";
}
May be this will work :
$w = "'".implode("','",$_POST['pal_num'])."'";
$rrr = mysql_query("SELECT * FROM pl_tab WHERE pal_num in (".$w.");");
...and may be you forgot a echo "<table>"; before the while :)