Rocketaka Posted March 3, 2007 Share Posted March 3, 2007 Hi I was trying to make my software script be able to validate the checkout process of multiple software entries. I also have it that when the admin validates the request to check out software that it will be logged in a seperate table. I can't seem to get it to work. When I look at the database software_logs table I'll see the entry is mostly "Array". Here's the code: if ( isset($_POST['checkout']) AND sizeof($_POST['checked']) ) { $ids = implode(',',$_POST['checked']); foreach ( $_POST['checked'] as $tmp ) { $title_list[] = $_POST['title'][$tmp]; $category_list[] = $_POST['category'][$tmp]; $by_list[] = $_POST['by'][$tmp]; $name_list[] = $_POST['name'][$tmp]; } $date = date("Y/m/d"); $id = $_POST['id']; $title = $_POST['title']; $category = $_POST['category']; $by = $_POST['by']; $name = $_POST['name']; $titles = implode(', ',$title_list); $sql = "UPDATE `software` SET `status` = 'Checked Out' WHERE `id` IN ($ids)"; $sql2 = "INSERT INTO `software_logs` (`title`, `category`, `status`, `by`, `name`, `date`) VALUES ('$title', '$category', 'Checked Out', '$by', '$name', '$date')"; mysql_query("$sql2") or die (mysql_error()); mysql_query("$sql") or die (mysql_error()); echo "You have checked out <b>".$titles."</b> successfully!\n"; } That's the code when the button is pressed. Here's the button for the actually table and checkboxes: <form onsubmit=\"return confirm('Do you really want to validate these request?');\" method='POST' action='index.php?cat=admin&page=checkout' name='checkbox' style='margin:0px;'> <input type='checkbox' onClick='Checkall(this.form);' style='margin-left:5px;'>Check All Requests<br>"; while ($data = mysql_fetch_array($query)) { if($class == $class1) { $class = $class2; } else { $class = $class1; } $id = $data['id']; $title = $data['title']; $category = $data['category']; $by = $data['by']; $name = $data['name']; echo "<tr class='$class'> <td width='50%'> <input type='checkbox' name='checked[]' value='$id'> <input type='hidden' name='title[$id]' value='$title'> <input type='hidden' name='category[$id]' value='$category'> <input type='hidden' name='by[$id]' value='$by'> <input type='hidden' name='name[$id]' value='$name'> ".$data['title']."</td> <td width='35%'>".$data['name']."</td> <td width='15%'>".$data['date']."</td> </tr>"; } echo "</table> <input type='submit' name='checkout' style='border:1px #1469A2 solid; margin-left:10px;' value='Validate Selected'> </form>"; Any help on this would be great! Thanks! Link to comment https://forums.phpfreaks.com/topic/40943-solved-logging-multiple-checkbox-entries/ Share on other sites More sharing options...
Rocketaka Posted March 3, 2007 Author Share Posted March 3, 2007 bump Link to comment https://forums.phpfreaks.com/topic/40943-solved-logging-multiple-checkbox-entries/#findComment-198726 Share on other sites More sharing options...
genericnumber1 Posted March 3, 2007 Share Posted March 3, 2007 your code is really messy... the reason you are getting the array being in the database problem is because you're doing just that... putting an array into the database. You make a multidimensional array of $_POST['by'][$tmp]; and then use it like it's a single dimensional array $_POST['by']; I hope I got you started on the right track, feel free to ask more questions of course. Link to comment https://forums.phpfreaks.com/topic/40943-solved-logging-multiple-checkbox-entries/#findComment-198731 Share on other sites More sharing options...
Rocketaka Posted March 3, 2007 Author Share Posted March 3, 2007 Yeah I know my code is messy. I just started learning PHP a couple months ago, so I'm still a novice. Anyways I have been able to get it to the point where it will store all of the information that has been checked but if their is more than one it will be in one row. For example the title field will have $software1, $software2, $software3 etc. I want to make a new row for each title that is checked. I tried doing this: if ( isset($_POST['checkout']) AND sizeof($_POST['checked']) ) { $ids = implode(',',$_POST['checked']); foreach ( $_POST['checked'] as $tmp ) { $title_list[] = $_POST['title'][$tmp]; $category_list[] = $_POST['category'][$tmp]; $by_list[] = $_POST['by'][$tmp]; $name_list[] = $_POST['name'][$tmp]; } $date = date("Y/m/d"); $info = array ( 'title' => '$title_list[]', 'cat' => '$category_list[]', 'by' => '$by_list[]', 'name' => '$name_list[]'); foreach ($info as $insert) { $sql2 = "INSERT INTO `software_logs` (`title`, `category`, `status`, `by`, `name`, `date`) VALUES ('$insert['']', '$insert['cat']', 'Checked Out', '$insert['by']', '$insert['name']', '$date')"; mysql_query("$sql2") or die (mysql_error()); } $titles = implode(', ',$title_list); $sql = "UPDATE `software` SET `status` = 'Checked Out' WHERE `id` IN ($ids)"; mysql_query("$sql") or die (mysql_error()); echo "You have checked out <b>".$titles."</b> successfully!\n"; } Didn't work. If anyone has any ideas on how to do that please tell me. Link to comment https://forums.phpfreaks.com/topic/40943-solved-logging-multiple-checkbox-entries/#findComment-198830 Share on other sites More sharing options...
Rocketaka Posted March 4, 2007 Author Share Posted March 4, 2007 Got the problem fixed. Here's the code incase someone has the same problem: if ( isset($_POST['checkout']) AND sizeof($_POST['checked']) ) { $ids = implode(',',$_POST['checked']); foreach ( $_POST['checked'] as $tmp ) { $title_list[] = $_POST['title'][$tmp]; $category_list[] = $_POST['category'][$tmp]; $by_list[] = $_POST['by'][$tmp]; $name_list[] = $_POST['name'][$tmp]; } $date = date("Y/m/d"); foreach ($title_list as $title) { $query = mysql_query("SELECT * FROM `software` WHERE `title` = '$title'"); $row = mysql_fetch_array($query); $category = $row['category']; $by = $row['by']; $name = $row['name']; $sql2 = "INSERT INTO `software_logs` (`title`, `category`, `status`, `by`, `name`, `date`) VALUES ('$title', '$category', 'Checked Out', '$by', '$name', '$date')"; mysql_query("$sql2") or die (mysql_error()); } $titles = implode(', ',$title_list); $sql = "UPDATE `software` SET `status` = 'Checked Out' WHERE `id` IN ($ids)"; mysql_query("$sql") or die (mysql_error()); echo "You have checked out <b>".$titles."</b> successfully!\n"; } echo "<a href='index.php?cat=admin&page=validate'>Go Back?</a>"; } I got rid of those hidden fields since they weren't needed <form onsubmit=\"return confirm('Do you really want to validate these request?');\" method='POST' action='index.php?cat=admin&page=checkout' name='checkbox' style='margin:0px;'> <input type='checkbox' onClick='Checkall(this.form);' style='margin-left:5px;'>Check All Requests<br>"; while ($data = mysql_fetch_array($query)) { if($class == $class1) { $class = $class2; } else { $class = $class1; } $id = $data['id']; $title = $data['title']; $category = $data['category']; $by = $data['by']; $name = $data['name']; echo "<tr class='$class'> <td width='50%'> <input type='checkbox' name='checked[]' value='$id'> <input type='hidden' name='title[$id]' value='$title'> ".$data['title']."</td> <td width='35%'>".$data['name']."</td> <td width='15%'>".$data['date']."</td> </tr>"; } echo "</table> <input type='submit' name='checkout' style='border:1px #1469A2 solid; margin-left:10px;' value='Validate Selected'> </form>"; Link to comment https://forums.phpfreaks.com/topic/40943-solved-logging-multiple-checkbox-entries/#findComment-198892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.