Jump to content

Deleting with check boxes..


Greysoul

Recommended Posts

seems as if every time i get something working i break something else. i have my main page that i display everything but i also always make a test.php to test things with. anyway...on my main page my check boxes delete fine..but on my new page that i've changed some things on..it doesn't work..1. the array for the delete box to display is the same2. the button is the same3. the query is the samei can't find the problem! ignore any changes with the table and other variables as thats working fine, i was changing some things with the updating porition..its just the deleting portion. whats different between the two?page where delete works

<form name='william' method='post' action=''><?php$bills="SELECT * FROM bills WHERE Owner = 'Both' OR Owner = 'William' ORDER BY Owner,DueDate";$result=mysql_query($bills);$count=mysql_num_rows($result);$x=0;while($row = mysql_fetch_array($result))  {$x++;echo "<tr><th class='centerbox'>" . "<input name='checkbox[]' type='checkbox' id='checkbox[]' value='" . $row['ID'] . "'>" . "</th><input type='hidden' size='10' name='id[$x]' class='form' value='" . $row['ID'] . "'><th>" . "<input type='text' size='10' name='wname[$x]' class='form' value='" . $row['Name'] . "'>" . "</th><td>" . "<input type='text' size='10' name='wpa[$x]' class='form' value='$" . $row['ProjAmnt'] . "'>" . "</td><td>" . "<input type='text' size='10' name='waa[$x]' class='form' value='$" . $row['ActAmnt'] . "'>" . "</td><td>" . "<input type='text' size='10' name='wdd[$x]' class='form' value='" . $row['DueDate'] . "'>" . "</td><td>" . "<input type='text' size='10' name='wc[$x]' class='form' value='" . $row['Company'] . "'>" . "</td>";if($row['PayMethod'] != check)echo "<td>" . '<a href="' . $row['PayMethod'] . '" target=_blank>' . 'Website </a>' . "</td></tr>";elseecho "<td>" . "Check" . "</td></tr>";// ++$x;  }$billtotals= mysql_query("SELECT SUM(ProjAmnt) AS projected, SUM(ActAmnt) AS actual FROM bills WHERE Owner = 'Both' OR Owner = 'William'");while($row = mysql_fetch_array($billtotals))  {$wbp=$row['projected'];$wba=$row['actual'];echo "<tr><th>" . "<input name='delete' class='button' type='submit' id='delete' value='DEL'>" . "</th><th>" . "Totals" . "</th><td>" . "$" . number_format($row['projected'],2) . "</td><td>" . "$" . $row['actual'] . "</td><th colspan='3' class='buttonbox'>" . "<input name='update' class='button' type='submit' id='update' value='Update'>" . "</th></tr></form>";  }

page where it doesn't work

<form name='update' method='post' action=''><table><tr><th colspan="2" class="centerbox">William's Bills</th><th colspan="5"> </th></tr><tr><th class='centerbox'><input type="checkbox" name="sAll" onClick="selectAll(this)" /></th><th>Bills</th><th>Project Amt</th><th>Actual Amnt</th><th>Due Date</th><th>Company</th><th>Pymnt Method</th></tr><?php$result = mysql_query("SELECT * FROM bills");$i = 0;while ($bills = mysql_fetch_array($result)) {echo "<input type='hidden' name='id[$i]' value='{$bills['ID']}'>";echo "<tr><th class='centerbox'>" . "<input name='checkbox[]' type='checkbox' id='checkbox[]' value='" . $bills['ID'] . "'>" . "</th><td><input type='text' size='15' class='form' name='name[$i]' value='{$bills['Name']}'></td><td><input type='text' size='15' class='form' name='projamnt[$i]' value='{$bills['ProjAmnt']}'></td><td><input type='text' size='15' class='form' name='actamnt[$i]' value='{$bills['ActAmnt']}'></td><td><input type='text' size='15' class='form' name='duedate[$i]' value='{$bills['DueDate']}'></td><td><input type='text' size='15' class='form' name='company[$i]' value='{$bills['Company']}'></td>";if($bills['PayMethod'] != check)echo "<td>" . '<a href="' . $bills['PayMethod'] . '" target=_blank>' . 'Website </a>' . "</td></tr>";elseecho "<td>" . "Check" . "</td></tr>";++$i;}$billtotals= mysql_query("SELECT SUM(ProjAmnt) AS projected, SUM(ActAmnt) AS actual FROM bills WHERE Owner = 'Both' OR Owner = 'William'");while($row = mysql_fetch_array($billtotals))  {$wbp=$row['projected'];$wba=$row['actual'];echo "<tr><th>" . "<input name='delete' class='button' type='submit' id='delete' value='DEL'>" . "</th><th>" . "Totals" . "</th><td>" . "$" . number_format($row['projected'],2) . "</td><td>" . "$" . $row['actual'] . "</td><th colspan='3' class='buttonbox'>" . "<input name='update' class='button' type='submit' id='update' value='Update'>" . "</th></tr></form>";  }

query that works on one page and not the other..

if($delete){$checkbox = $_POST['checkbox'];$delete = $_POST['delete'];for($i=0;$i<$count;$i++){$del_id = $checkbox[$i];$sql = "DELETE FROM bills WHERE ID='$del_id'";$result = mysql_query($sql);}if($result){echo "<meta http-equiv=\"refresh\" content=\"0;URL=test.php\">";}}

Link to comment
Share on other sites

I'm glad you solved your problem. There's no better feeling than solving a problem that has been haunting you for a while. May I ask why you are leaving out delimiters for your if statements in both pages (line 19 on page 1 and line 33 on page 2)?

Link to comment
Share on other sites

I'm glad you solved your problem. There's no better feeling than solving a problem that has been haunting you for a while. May I ask why you are leaving out delimiters for your if statements in both pages (line 19 on page 1 and line 33 on page 2)?
i'm sort of a beginner, i don't even know what a delimiter is
Link to comment
Share on other sites

i'm sort of a beginner, i don't even know what a delimiter is
In this case the delimiter of a function is the curly braces ({}) of a function.
if(statement){	//code to be executed if true}else{	//code to be executed if statement is not true}

Link to comment
Share on other sites

In this case the delimiter of a function is the curly braces ({}) of a function.
if(statement){	//code to be executed if true}else{	//code to be executed if statement is not true}

i remember trying to do it and getting errors, so i took them out and it worked. i was more than likely putting them in wrong. if it works, then is it required?
Link to comment
Share on other sites

i remember trying to do it and getting errors, so i took them out and it worked. i was more than likely putting them in wrong. if it works, then is it required?
Apparently not. However it did throw me off when looking at your code. I believe it is best practice to put them in there.One reason you might have gotten an error is if you did it like this:
if(statement){	//code to be executed if trueelse	//code to be executed if statement is not true}

Notice the else statement is missing its own pair of curly brackets.Here is an example of proper use of the curly brackets:

if(statement){	//code to be executed if true}else{	//code to be executed if statement is not true}

Link to comment
Share on other sites

May I ask why you are leaving out delimiters for your if statements in both pages (line 19 on page 1 and line 33 on page 2)?
Brackets or braces would have been better terminology. A delimiter is something used to separate a list of items. Like a comma: red,orange,green,blue
Link to comment
Share on other sites

Brackets or braces would have been better terminology. A delimiter is something used to separate a list of items. Like a comma: red,orange,green,blue
Why? Isn't the purpose of a set of delimiters to mark the boundaries of something (in this case the boundaries of the conditional statement)?
Link to comment
Share on other sites

Why? Isn't the purpose of a set of delimiters to mark the boundaries of something (in this case the boundaries of the conditional statement)?
yes, but I think the context here is that of scoping, not delimiting.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...