PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gilly79
Forum Newbie
Posts: 3 Joined: Mon Feb 22, 2010 4:48 pm
Post
by gilly79 » Mon Feb 22, 2010 4:52 pm
Hello Im really sorry i need help
Im trying to put a checkbox in a returned query from a database i.e echo row with a ceckbox so i can delete the row...
Its just not working, tried messing aroun with the parms and nothing works
below is the code could someone please help its driving me insaine!!
Code: Select all
<?php
// Start the session
require_once('startsession.php');
// Insert the page header
$page_title = 'Inbox';
require_once('header.php');
// ========== SCOTT ==============
//Include the connection details, open $connection and select database
//include ("connection.php");
require_once('connectvars.php');
//vars
$user_id = $_SESSION['user_id'];
echo $user_id;
//Prepare query
$query = "SELECT * FROM MESSAGES WHERE MessageTo='$user_id' ";
// execute query
$result = mysqli_query($dbc,$query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysqli_num_rows($result)>0) {
echo "<table border=1>\n<tr>" .
"<th>MessageNo</th>" .
"<th>MessageFrom</th>" .
"<th>MessageTo</th>" .
"<th>Subject</th>" .
"<th>Message</th>".
"<th>Reply</th>".
"<th>Delete</th>";
while ($row = @ mysqli_fetch_array($result)) {
//while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td >".$row["MessageNo"]."</td>";
echo "<td>".$row["MessageFrom"]."</td>";
echo "<td>".$row["MessageTo"]."</td>";
echo "<td>".$row["Subject"]."</td>";
echo "<td>".$row["Message"]."</td>";
echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$row['MessageNo']\" />";
echo "<td class=BorderMeRed>".$row["MessageNo"]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
print "No rows found!";
}
?>
<?php
// Include the formatted error message
/* if (isset($_SESSION['message']))
echo
"<h3><font color=red>".$_SESSION['message']."</font></h3>"; */
?>
<p>Click<a href="tester.php">Here</a>to send a message<p/>
<?php
require_once('footer.php');
?>
Last edited by
Benjamin on Mon Feb 22, 2010 8:45 pm, edited 1 time in total.
Reason: Added [code=php] tags.
dzelenika
Forum Newbie
Posts: 10 Joined: Sat Feb 20, 2010 2:29 pm
Post
by dzelenika » Mon Feb 22, 2010 5:15 pm
your checkbox tag should be in <td> </td>, instead between two td tags
gilly79
Forum Newbie
Posts: 3 Joined: Mon Feb 22, 2010 4:48 pm
Post
by gilly79 » Mon Feb 22, 2010 5:29 pm
like so??
Code: Select all
echo "<td><input type=\"checkbox\" name=\"delete[]\" value=\"$row['MessageNo']\" /> </td>";
still an error
Last edited by
Benjamin on Mon Feb 22, 2010 8:46 pm, edited 2 times in total.
Reason: Added [code=php] tags.
dzelenika
Forum Newbie
Posts: 10 Joined: Sat Feb 20, 2010 2:29 pm
Post
by dzelenika » Mon Feb 22, 2010 5:42 pm
gilly79 wrote: like so??
echo "<td><input type=\"checkbox\" name=\"delete[]\" value=\"$row['MessageNo']\" /> </td>";
still an error
what error?
gilly79
Forum Newbie
Posts: 3 Joined: Mon Feb 22, 2010 4:48 pm
Post
by gilly79 » Mon Feb 22, 2010 5:54 pm
im using text textmate and the messageno is being highlighted - there is a definate error as my page wont load.... im not sure if the td is an error to be honest as i know you can do checkboxes without them...
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon Feb 22, 2010 8:50 pm
Use
Code: Select all
tags when posting code in the forums.
The solution to this issue is relatively simple. Rather than tell you, I will direct you.
Please see: http://www.php.net/manual/en/language.t ... ng.complex
realnsleo
Forum Newbie
Posts: 15 Joined: Sat May 16, 2009 12:08 pm
Post
by realnsleo » Tue Feb 23, 2010 1:29 am
Try this:
Code: Select all
if (mysqli_num_rows($result)>0) { // Or $result->num_rows() > 0
echo "<table border=1>".
"<tr>" .
"<th>MessageNo</th>" .
"<th>MessageFrom</th>" .
"<th>MessageTo</th>" .
"<th>Subject</th>" .
"<th>Message</th>".
"<th>Reply</th>".
"<th>Delete</th>".
"</tr>"; // you forgot to add this ending tag
while ($row = @ mysqli_fetch_array($result)) { // or $result->fetch_assoc()
echo '<tr>'.
'<td>'. $row["MessageNo"]. '</td>';
'<td>'. $row["MessageFrom"]. '</td>';
'<td>'. $row["MessageTo"]. '</td>';
'<td>'. $row["Subject"]. '</td>';
'<td>'. $row["Message"]. '</td>';
'<td class="BorderMeRed">' .$row["MessageNo"]. '</td>';
'<td><input type="checkbox" name="delete[]" value="'. $row['MessageNo']. '" />';
'</tr>';
}
echo "</table>";
}
else {
// no
// print status message
print "No rows found!";
}