chriscloyd Posted December 29, 2006 Share Posted December 29, 2006 heres my delima okay I want to check a form and if there is multi errors i want it to show all errors at once heres my code[code]<?php//connect to mysqlmysql_connect('localhost','root','');mysql_select_db('site');//register begins//define vars$first = $_POST['first'];$last = $_POST['last'];$username = $_POST['username'];$password = $_POST['password'];$password2 = $_POST['password2'];$email = $_POST['email'];$email2 = $_POST['email2'];$day = $_POST['day'];$month = $_POST['month'];$year = $_POST['year'];$key = $_SESSION['key'];session_destroy('key');$sc = $_POST['sc'];$hostname = $_SERVER["HTTP_HOST"];$ip = $_SERVER['REMOTE_ADDR'];//check them allif (!$first) { $error = '-You did not supply your First Name'; $complete = 0;} elseif (!$last) { $error = '-You did not supply your Last Name'; $complete = 0;} elseif (!$username) { $error = '-You did not supply a Username'; $complete = 0;} elseif (!$password) { $error = '-You did not supply a Password'; $complete = 0;} elseif (!$password2) { $error = '-You did not supply a Confirmation Password'; $complete = 0;} elseif (!$email) { $error = '-You did not supply your Email address'; $complete = 0;} elseif (!$email2) { $error = '-You did not supply your Confirmation Email address'; $complete = 0;} elseif (!$day) { $error = '-You did not supply your Birthday day'; $complete = 0;} elseif (!$month) { $error = '-You did not supply your Birthday month'; $complete = 0;} elseif (!$year) { $error = '-You did not supply your Birthday year'; $complete = 0;} elseif (!$sc) { $error = '-You did not supply the Security Code'; $complete = 0;} if ($complete == 0) { //go back to page and display errors}?>[/code]at the bottom if $complete == 0 i want it to go back and show all the errors is there a way of showing all the errors at once? Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 Put all the errors into an array. So instead of...[code=php:0]$error = '-You did not supply your First Name';[/code]Use...[code=php:0]$error[] = '-You did not supply your First Name';[/code]Then....[code=php:0]if ($complete == 0) { foreach($errors as $error) { echo $error."<br />"; }}[/code] Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted December 29, 2006 Author Share Posted December 29, 2006 okay but im wanting it to redirect to the register page and show the errors} Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 Well, in that case you would be best to store the errors in the session array. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted December 29, 2006 Author Share Posted December 29, 2006 session array so would that be like $_SESSION['errors'] = $errors[]and then on the register pageforeach($_SESSION['errors'] as $error) { echo $error."<br />"; } Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 Put session_start() at the top of both pages. Store your errors using something like....[code=php:0]$_SESSION['error'][] = "your error message";[/code]then, after you redirect back use something allong the lines of.[code=php:0]if (isset($_SESSION['error'])) { foreach($_SESSION['error'] as $error) { echo $error."<br />"; }}[/code] Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted December 29, 2006 Author Share Posted December 29, 2006 i can then kill the session right by doingsession_destroy('error'); Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 Theres no need, but yes you could. session_distroy takes no arguments though. 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.