pianoman993 Posted June 30, 2008 Share Posted June 30, 2008 I am having a heck a of a time trying to insert an array into an array. To illustrate this, I am using an array called $errors and trying to insert the values from $errors into an array called $problems like so: array( *errors array values here* ); AHH!! heelp! much thanks - mark Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 30, 2008 Share Posted June 30, 2008 Can you post the code you have already that's giving you problems between tags? Ken Quote Link to comment Share on other sites More sharing options...
itsjareds Posted June 30, 2008 Share Posted June 30, 2008 Try the implode() function. $err = implode(" ,", "$error"); array($err); Tell me if this doesn't work, I'm not an expert. Quote Link to comment Share on other sites More sharing options...
pianoman993 Posted June 30, 2008 Author Share Posted June 30, 2008 Thanks for the help so far, I hope this code can make things more specific: Here's one page's code: if (empty($_POST['username'])) { $errors = 'Please enter your username'; } else { $username = $_POST['username']; global $username; } if ( (empty($_POST['password'])) || (empty($_POST['conf_password'])) ) { $errors = 'Please enter your password'; } else { $password = $_POST['password']; global $password; } if ( (empty($_POST['email'])) || (empty($_POST['conf_email'])) ) { $errors = 'Please enter your email'; } else { $email = $_POST['email']; global $email; } if ($errors) { $data['problems'] = array('One','Two'); $this->template->load('register/register_view',$data); } else { echo 'Huge Success!'; } The second page's code using information from the first page: <?php if (isset($problems)) { foreach($problems as $message) echo "$message<br />"; } ?> <b>Registration Page</b> <div id="registration"><table> <?=form_open('register/handle')?> <tr><td>Username:</td><td><input type="text" name="username" /></td></tr> <tr><td>Password:</td><td><input type="password" name="password" /></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="conf_password" /></td></tr> <tr><td>Email:</td><td><input type="text" name="email" /></td></tr> <tr><td>Confirm Email:</td><td><input type="text" name="conf_email" /></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Register" /></td></tr> </table></div><!--Registration--> My goal is to somehow get out all of the values from the $errors array and insert them... $data['problems'] = new array( *right here* ) Quote Link to comment Share on other sites More sharing options...
itsjareds Posted June 30, 2008 Share Posted June 30, 2008 see my post above Quote Link to comment Share on other sites More sharing options...
pianoman993 Posted June 30, 2008 Author Share Posted June 30, 2008 I tried your method however I got an error message: Here is what I used as my code: Message: implode() [function.implode]: Invalid arguments passed $pointer = implode(",","$errors"); $data['problems'] = array($pointer); It seemed I was closest when I used print_r Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 30, 2008 Share Posted June 30, 2008 Here's how I would code your pages: <?php session_start(); $errors = array(); if (empty($_POST['username'])) { $errors[] = 'Please enter your username'; } else { $_SESSION['username'] = $_POST['username']; } if ( (empty($_POST['password'])) || (empty($_POST['conf_password'])) ) { $errors[] = 'Please enter your password'; } else { $_SESSION['password'] = $_POST['password']; } if ( (empty($_POST['email'])) || (empty($_POST['conf_email'])) ) { $errors[] = 'Please enter your email'; } else { $_SESSION['email'] = $_POST['email']; } if (!empty($errors)) { $_SESSION['errors'] = $errors; $data['problems'] = true; $this->template->load('register/register_view',$data); } else { echo 'Huge Success!'; } ?> And <?php session_start(); if ($data['problems']) { echo implode("<br>\n",$_SESSION['errors']) . "<br>\n"; } ?> <b>Registration Page</b> <div id="registration"><table> <?=form_open('register/handle')?> <tr><td>Username:</td><td><input type="text" name="username" /></td></tr> <tr><td>Password:</td><td><input type="password" name="password" /></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="conf_password" /></td></tr> <tr><td>Email:</td><td><input type="text" name="email" /></td></tr> <tr><td>Confirm Email:</td><td><input type="text" name="conf_email" /></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Register" /></td></tr> </table></div><!--Registration--> I replaced the lines of the type "global $variable" with "$_SESSION['variable'] = $_POST['variable'], since the "global" keyword is meaningless in this context. Ken Quote Link to comment Share on other sites More sharing options...
pianoman993 Posted June 30, 2008 Author Share Posted June 30, 2008 THanks for the code rework however, it still does not solve the problem. I may in the end just recode the pages to some sort of unconventional technique to solve the problem. 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.