Jump to content

Checkboxs and URL's


robcrozier

Recommended Posts

Hi,

right what i've got is a large print out of info from one of my database tables and what i want to do is to create a checkbox next to each row that is printed out. i want to then be able to select one or more of these checkboxes and click a button which will send all of the values from the checkboxes throught the URL to another page. All of the chexkboxes will use the same table datum to pass throught the url but, being the primary key, each value will be different.

heres some code that ive got so far. This prints out all of the entries and places a checkbox next to each one:

[code]
<?php
echo "<br>";
echo "<center><table width = '100%' align ='center'><tr><td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Number :<b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Username :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>DVD Title :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Date :</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Sent:</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Recieved:</b></font></td>";

  while($nt=mysql_fetch_array($r))
  {
    echo "<tr>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_number]</td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'><a href='view_customer_records.php?username=$nt[username]'>$nt[username]</a></font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[dvd_title]</font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_date]</font></td>
<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>

<form name='sent' action='update_sent_orders.php' method='POST'>
<div align='center'><br>
<input type='checkbox' name='sent' value='$nt[order_number]'></div></form> </font></td>


<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>

<form name='recieved' action='update_recieved_orders.php' method='POST'>
<div align='center'><br>
<input type='checkbox' name='sent' value='$nt[order_number]'></div></form></font></td>
<td align ='left' width ='20%'><a href='delete_order.php?order_number=$nt[order_number]'>Delete</a></td></tr>";
  }
  echo"</center></table>";

  ?>

[/code]

what i need help with is adding the final button which will send all of the information and also guidance on how to send the stuff through the url.

Note: the order number is the value i want to send!
Link to comment
Share on other sites

Well first off you cannot have 2 forms an a page. You will have to do it with one for.

You will have to update sent and recieved orders on the same page. Good news is that it is easily done

I do not knwo what your pages are called but here is what I did

orders.php //just a name i gave it
[code]<?
// Start your checkbox numbers, They cannot be the same name
$s = '1';
$re = '1';
echo "<br>";
echo "<center><table width = '100%' align ='center'><tr><td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Number :<b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Username :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>DVD Title :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Date :</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Sent:</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Recieved:</b></font></td>";

  while($nt=mysql_fetch_array($r))
  {
    echo "<tr>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_number]</td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'><a href='view_customer_records.php?username=$nt[username]'>$nt[username]</a></font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[dvd_title]</font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_date]</font></td>
<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'></td>

<form name='sent' action='update_orders.php' method='POST'>
<div align='center'><br>
<input type='checkbox' name='sent".$s."' value='$nt[order_number]'></div></font></td>
<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'></td>
<div align='center'><br>
<input type='checkbox' name='rec".$re."' value='$nt[order_number]'></div></form></font></td>
<td align ='left' width ='20%'><a href='delete_order.php?order_number=$nt[order_number]'>Delete</a></td></tr>";
// Add one to the names
$s++;
$re++;
}
echo"<tr><td colspan=7><input type=submit></td></tr></center></form></table>";
?>[/code]

update_orders.php
[code]<?php
$ids = '';
$sarray = array();
$rarray = array();
$send = 'sent';
$receive = 'rec';
foreach ($_POST as $key => $value) {
  $ids .= "$key=$value&";
  if (substr($key, 0, 4) == $send) {
    $sarray[]= $value;
  }
  if (substr($key, 0, 3) == $receive) {
    $rarray[]= $value;
}
}
$sentids = implode(", ", $sarray);
$recids = implode(", ", $rarray);

// sent query
$update_sql = "UPDATE order SET
              sent = 'check' WHERE id IN ($sentids)";

// receive query
$receive_sql = "UPDATE order SET
              receive = 'check' WHERE id IN ($recids)";
?>[/code]

Hope that helps

Ray
Link to comment
Share on other sites

Enclose all checkboxes in same form and name them as "sent[]" so they get posted in a single array.

I'm using POST but if you specifically want a querystring, use GET.

Here's a simplified snippet to show how it works
[code]
<?php

if (isset($_POST['sent'])) {
    foreach($_POST['sent'] as $ono) {
            echo "$ono<br>";
    }
}
?>
<FORM method='POST'>
<INPUT TYPE="CHECKBOX"  name="sent[]" value="1">One<BR>
<INPUT TYPE="CHECKBOX"  name="sent[]" value="2">Two<BR>
<INPUT TYPE="CHECKBOX"  name="sent[]" value="3">Three<BR>
<INPUT TYPE="SUBMIT"  name="submit" value="Submit">
</FORM>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.