Jump to content

[SOLVED] Inserting 2 records into a table when checkbox is checked


mikebyrne

Recommended Posts

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

ok change this too

 

<td width="172"><input type="text" name="trackno_<?php echo $row['OrderNo];?>" value="<?php echo htmlspecialchars($row['Trackno']);?>" /></td>

 

and your code too

function fnGetTrackNum($arrPost)
{
   $arrReturn = array();
   foreach ($arrPost as $strKey => $strValue)
   {
       if (preg_match("/^trackno_/",$strKey)
       {
                $arrReturn[preg_replace("/^trackno_/","",$strKey)] = $strValue;
       }

   }
return $arrReturn

}

$arrTrackNo = fnGetTrackNum($_POST);
foreach($arrTrackNo as $OrderNo => $text){
  $text = mysql_real_escape_string(trim($text));
  $sql = "UPDATE $tbl1 SET Trackno = '{$text}' WHERE OrderNo= '{$OrderNo}'";
  mysql_query($sql) or die("Failed on order {$OrderNo}");
}

Link to comment
Share on other sites

ok the function should of been... lol made loads of errors in the syntax because i was not actually testing the code...

 

function fnGetTrackNum($arrPost)
{
   $arrReturn = array();
   foreach ($arrPost as $strKey => $strValue)
   {
       if (preg_match("/^trackno_/",$strKey))
       {
                $arrReturn[preg_replace("/^trackno_/","",$strKey)] = $strValue;
       }

   }
return $arrReturn;

}

Link to comment
Share on other sites

Failed on order 9695959

mysql Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET Trackno = 'KKKK' WHERE OrderNo= '9695959'' at line 1

Sql:UPDATE SET Trackno = 'KKKK' WHERE OrderNo= '9695959'

Link to comment
Share on other sites

The default for the Trackno is Null

 

-- ----------------------------

-- Table structure for admin

-- ----------------------------

CREATE TABLE `admin` (

  `OrderNo` decimal(8,0) default NULL,

  `Orderdate` date default NULL,

  `Custname` char(10) collate latin1_general_ci default NULL,

  `Dispatchdate` date default NULL,

  `Trackno` decimal(8,0) default NULL,

  `Amount` decimal(5,0) default NULL,

  `Shippingmet` char(255) collate latin1_general_ci default NULL,

  `Ordercompleted` decimal(10,0) default NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

-- ----------------------------

 

 

Link to comment
Share on other sites

The form for unprocessed.php is

 

<form action = "processed.php" method="post">		
<table width="850" border="0" cellspacing="0" cellpadding="0">
<?php
// let's get some data
include('adminconnect.php');
$sql = mysql_query("SELECT OrderNo, Orderdate, Custname, Amount, Shippingmet FROM admin WHERE Ordercompleted = 0");
while( $row = mysql_fetch_array($sql) ) {
// loop through and display
?>

<tr align="left">
<td width="33"> </td>
<td><input type = "checkbox" name="order[<?php echo $row['OrderNo'];?>]" value="checked"></td>
<td width="33"> </td>
<td width="82"><a href="javascript:openWindow('popup_detail.html', 'NewWindow', 615, 600)" class="black"><?php echo $row['OrderNo'];?></a></td>  
<td width="61" align="center"><?php echo $row['Orderdate'];?></td>
<td width="230" align="Left"><?php echo $row['Custname'];?></td>
<td width="172"><input type="text" name="trackno_<?php echo $row['OrderNo'];?>" value="<?php echo htmlspecialchars($row['Trackno']);?>" /></td>
<td width="56" align="right"><?php echo $row['Amount'];?></td>
<td width="21"> </td>
<td width="136" align="center"><?php echo $row['Shippingmet'];?></td>
</tr>
<?
}
?>
</table>

    <!-- data finish -->
                     
            <!-- -->
        <div id="btn">
          <input type="submit" value="Process">
        </div>
        <div class="clr">
          <!-- -->
        </div>

        <div class="padTop16">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
        <!-- btn finish -->
      <div class="clr">

        <!-- -->
      </div>
      <!-- data content finish -->
      </form>

 

Link to comment
Share on other sites

<?php
include('adminconnect.php');
function fnGetTrackNum($arrPost)
{
   $arrReturn = array();
   foreach ($arrPost as $strKey => $strValue)
   {
       if (preg_match("/^trackno_/",$strKey))
       {
                $arrReturn[preg_replace("/^trackno_/","",$strKey)] = $strValue;
       }

   }
return $arrReturn;

}

$arrTrackNo = fnGetTrackNum($_POST);
foreach($arrTrackNo as $OrderNo => $text){
  $text = mysql_real_escape_string(trim($text));
  $sql = "UPDATE $tbl1 SET Trackno = '{$text}' WHERE OrderNo= '{$OrderNo}'";
  mysql_query($sql) or die("Failed on order {$OrderNo}<BR>mysql Error:".mysql_error()."<BR>Sql:".$sql);
}
?>

 

Link to comment
Share on other sites

change

 

<td><input type = "checkbox" name="order[<?php echo $row['OrderNo'];?>]" value="checked"></td>

 

to

 

<td><input type = "checkbox" name="order[]" value="<?php echo $row['OrderNo'];?>"></td>

 

change

 

foreach($arrTrackNo as $OrderNo => $text){
  $text = mysql_real_escape_string(trim($text));
  $sql = "UPDATE $tbl1 SET Trackno = '{$text}' WHERE OrderNo= '{$OrderNo}'";
  mysql_query($sql) or die("Failed on order {$OrderNo}<BR>mysql Error:".mysql_error()."<BR>Sql:".$sql);
}

 

to

 

foreach ($_POST['order'] as $strKey => $strValue)
{
  $text = mysql_real_escape_string(trim($arrTrackNo[$strValue]));
  $sql = "UPDATE $tbl1 SET Ordercompleted='1',Trackno = '{$text}' WHERE OrderNo= '{$strValue}'";
  mysql_query($sql) or die("Failed on order {$OrderNo}<BR>mysql Error:".mysql_error()."<BR>Sql:".$sql);

}

 

and your done....

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.