rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 hmmm... I see what you mean I need to review the whole script... Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452194 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452207 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 Thanks for yuor help but im getting another Parse error: syntax error, unexpected T_STRING, expecting ']' in C:\xampp\htdocs\Admin_files\Unprocessed.php on line 223 Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452218 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 Sorry that was my mistake again forgot the single quote should be <td width="172"><input type="text" name="trackno_<?php echo $row['OrderNo'];?>" value="<?php echo htmlspecialchars($row['Trackno']);?>" /></td> Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452220 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 Getting closer! But getting an error on processed.php Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\Admin_files\processed.php on line 8 Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452224 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452231 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 No problem you help is REALLY apricated! Getting the error Failed on order 9695959 Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452239 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 there must be a mysql error change mysql_query($sql) or die("Failed on order {$OrderNo}"); to mysql_query($sql) or die("Failed on order {$OrderNo}<BR>mysql Error:".mysql_error()."<BR>Sql:".$sql); and tell me what error you get Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452245 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452247 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 seeing the error it seems the $tbl1 table variable is null however I saw it defined in your script can you double check if its defined paste your whole script again... Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452248 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452251 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452257 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 what about process.php Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452259 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 <?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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452264 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 got it change <?php include('adminconnect.php'); too <?php include('adminconnect.php'); $tbl1 = "admin"; and it should work! Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452273 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 That seems to put 0 in all Tracno fields as opposed to the user input Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452284 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 your track number is decimal format in the database are you entering alphabets ? only enter digits Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452291 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 Ah ok, thanks The only problem left is getting the 1 to post into the Orderscompleted field Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452295 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 this "UPDATE $tbl1 SET Trackno = '{$text}' WHERE OrderNo= '{$OrderNo}'"; should be "UPDATE $tbl1 SET Ordercompleted='1',Trackno = '{$text}' WHERE OrderNo= '{$OrderNo}'"; Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452296 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 Thats turned ALL the Orderscompleted to 1 Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452301 Share on other sites More sharing options...
adam291086 Posted January 29, 2008 Share Posted January 29, 2008 that means that there is a problem with $OrderNo. Echo it out to see that the value is. Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452304 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452308 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 I updated the code but it still just puts 1 in all the Ordercompleted Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452315 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 hmm.. it will only mark the orders complete which you checked... did you check all the orders... Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452316 Share on other sites More sharing options...
mikebyrne Posted January 29, 2008 Author Share Posted January 29, 2008 No just checked 1 order Link to comment https://forums.phpfreaks.com/topic/88226-solved-inserting-2-records-into-a-table-when-checkbox-is-checked/page/2/#findComment-452321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.