AdRock Posted October 12, 2008 Share Posted October 12, 2008 I am having a nightmare passing a variable in the header function to be passed to another page. What i want to do is check a checkbox (which is in an array) and pass that to the header function. When i click the button which processes the form it puts id=Array in the url instead of the id of the record. It must be something to do with this line or is it? I'm stumped. echo "<td class='tdleft'><input type='checkbox' name='id[{$row['id']}]' value='{$row['id']}' /></td>"; <?php require_once('../php/database/MySQL.php'); require_once('../php/database/connection.php'); require_once('../php/init.php'); require_once('php/script.php'); if (!is_authed_admin()) { header('Location: http://www.jackgodfrey.org.uk'); } /** * The home page of the website */ // The title of the page $title = "Sponsors / Supporters"; // Validate the form if($_POST && array_key_exists("action", $_POST)){ // CARRY OUT SANITIZATION AND DATA VALIDATION HERE!!!!!!!!! $db = & new MySQL($host,$dbUser,$dbPass,$dbName); // CARRY OUT RELAVANT ACTION switch($_POST['action']) { case "back": header('Location: index.php'); break; case "edit": $id = check_input($_POST['id']); header('Location: edit-sponsor.php?id='.$id); break; case "add": header('Location: add-sponsor.php'); break; case "delete": if(!empty($_POST['id'])) { $id = check_input($_POST['id']); $result = content_delete('sponsors', 'id', $id); if ($result == 'Correct') { header('Location: delete-success.php'); } else { $delete_error = $result; } } break; } } $path = "sponsors"; $webpage = basename($path); $db = & new MySQL($host,$dbUser,$dbPass,$dbName); $count="Select COUNT(*) from sponsors"; $sql="SELECT * FROM sponsors"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); // Perform a query getting back a MySQLResult object $res = $db->query($count); $result = $db->query($sql); //get the number of rows in datatbase $getresult = $result->size(); $numrows = $res->fetchrow(); if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); $entries_per_page = 30; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); $sql="SELECT id,name, location, url FROM sponsors ORDER BY name ASC LIMIT $offset,$entries_per_page"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); $err = $result->size(); // Include the header html require_once("header.inc.php"); echo ( "<h1>Sponsors / Supporters</h1>"); ?> <form id="adminform" name="adminform" action="<?php $_SERVER['REQUEST_URI'] ?>" method="post"> <input type="button" class="back" id="backbutton" title="go back" onclick="performAction('back');" /> <input type="button" class="delete" id="deletebutton" title="delete" onclick="performAction('delete');" /> <input type="button" class="edit" id="editbutton" title="edit" onclick="performAction('edit');" /> <input type="button" class="add" id="addbutton" title="add" onclick="performAction('add');" /> <table id="admintable"> <tr><th class='tdleft'> <?php if($err !=0) { echo"<input type='checkbox' name='all' onclick='checkAll(adminform);' />"; } echo "</th><th class='tdName'>Name</th>"; echo "<th class='tdLoc'>Location</th>"; echo "<th class='tdURL'>URL</th>"; $z = 0; // Iterate through the results while ($row = $result->fetch()) { if($z % 2==0) { //this means if there is a remainder echo "<tr class='yellow'>\n"; $z++; } else { //if there isn't a remainder we will do the else echo "<tr class='white'>\n"; $z++; } echo "<td class='tdleft'><input type='checkbox' name='id[{$row['id']}]' value='{$row['id']}' /></td>"; echo "<td class='tdName'>{$row['name']}</td>"; echo "<td class='tdLoc'>{$row['location']}</td>"; echo "<td class='tdURL'>{$row['url']}</td></tr>"; } ?> </table> <input type="hidden" id="action" name="action" value="" /> </form> <?php //or after the results if($getresult > 1) pagination_one($total_pages,$page); // Include the footer html require_once("footer.inc.php"); ?> Link to comment https://forums.phpfreaks.com/topic/128124-adding-variable-to-header-location-function/ Share on other sites More sharing options...
DarkWater Posted October 12, 2008 Share Posted October 12, 2008 In order to transmit an array, you'd need something like: <?php header(sprintf('Location: http://www.something.com/redirect.php?id=%s', urlencode(serialize($array)))); ?> You then need to run unserialize(urldecode($_GET['id'])) on the receiving page. Or just use sessions. Link to comment https://forums.phpfreaks.com/topic/128124-adding-variable-to-header-location-function/#findComment-663524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.