shotos Posted July 22, 2008 Share Posted July 22, 2008 hi, i designed a form which allows a user to enter how many entries he wld want to make then the form is displayed for him to make the first entry, after the data entered is stored in an array, the form is re-displayed again until all entries have been entered. problem is when i use print_r() to output, only the last entry is outputted. <?php session_start(); ob_start(); if(!isset($_POST['submit'] )) { ?> <head> <link rel="stylesheet" type="text/css" href="new.css" /> <title>Checklist System</title> </head> <body> <div id="container"> <div id="banner"> <h1>Checklist System</h1> </div> <div id="nav"color="backgrounds/blue01"> Welcome <?php echo $_SESSION['user'] ?><br><br><br> <a href="view_users.php">View Users</a><br><br><a href="create_User.php">Create User Accounts</a><br><br><a href="edit_delete_user.php">Edit/Delete User</a><br><br><a href="end.php">Generate Checklist</a><br><br><a href="login_success.php">View all Checklists</a><br><br><br><a href="log_out.php">Sign Out</a> </div> <div id="content"> <h2>Enter Check Item and its Properties </h2> <form method="POST" action="<?php $_SERVER['PHP_SELF']?>"> <table border="0" align="center" cellpadding="10" cellspacing="10"> <tr> <td>Check Item: <input type="text" name="checkItem"></td></tr> <tr><td><h3>Select Check Item's Corresponding Checklist Element</h3></td></tr> <tr> <td><input type="radio" name="element" value="radio">Radio Button<br></td> </tr> <tr> <td><input type="radio" name="element" value="checkbox">Checkbox<br></td> </tr> <tr> <td><input type="radio" name="element" value="text">Textbox<br></td> </tr> <tr><td> </td></tr> <tr><td><h3>Enter Labels for the chosen checklist element</h3></td></tr> <td><FONT color="red" size="1">***enter labels seperated by commas***</FONT></td></tr> <tr> <td>Label : <input type="text" name="label" size="50"></td></tr> <tr><td> </td></tr> <tr> <td ><input type="hidden" id="num" name="num" value="<?php echo $_SESSION['count'];?>"> </td></tr> <tr> <td align="center"><input type="submit" name="submit" value="Submit"> </td></tr> </table> </form> </div> </div> </body> <?php } else { $num = $_POST['num']; $check_item[$num]['checkitem'] = $_POST['checkItem']; $check_item[$num]['element'] = $_POST['element']; $check_item[$num]['label'] = $_POST['label']; /*foreach($_POST as $var) { $check_item[] = $var; }*/ //unset($_POST); $_SESSION['count'] = ++$num ; if($num == $_SESSION['num_Items']) { $_SESSION['checks'] = $check_item ; header("location:checking1.php?item=$check_item"); } else { header("location:checking.php"); } } ob_flush(); ?> Quote Link to comment Share on other sites More sharing options...
s0c0 Posted July 22, 2008 Share Posted July 22, 2008 This most likely means you keep overwriting the array. You should just be able to do something like: $array[]=$new_value; This will keep incrementing the index by one each time you add something to the array. Quote Link to comment Share on other sites More sharing options...
shotos Posted July 22, 2008 Author Share Posted July 22, 2008 i keep getting only the last entry. Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 22, 2008 Share Posted July 22, 2008 array's don't persist from page to page and you can only transmit serialized data (text) through a get or post request. You can't pass an array like you can with a function call, so header("location:checking1.php?item=$check_item"); Isn't doing what you think it is. Ideally, this is performed with a database, which stores the user's entry on every submit... or by allowing the user to input all info at once. If you insist on this format, I supposed you could try to serialize() the array first, pass it through $_GET and then unserialize() it on the other side, but that would get messy in a hurry Quote Link to comment Share on other sites More sharing options...
s0c0 Posted July 23, 2008 Share Posted July 23, 2008 Or store it in the session or even in a cookie if its small enough. There is a class out there that stores arrays in cookies by serializing them. Just look in PHPs documentation on cookies, it was posted there by a user a while back. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.