seanpearman Posted September 7, 2007 Share Posted September 7, 2007 Hi guys, just wondered if anyone can help me understand where to insert my include function to pull in my "design". //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } I want the following responses to be in my overall site design instead of simple text and white background: -'You did not complete all of the required fields' -'Sorry, the username '.$_POST['username'].' is already in use.' -'Your passwords did not match.' Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/68332-adding-design-to-php/ Share on other sites More sharing options...
Fearpig Posted September 7, 2007 Share Posted September 7, 2007 Hello, I usually sort out any header information, declare any variables, include the start of my design, do something here!, include the end of my design: e.g. - session bits - get/post variables - validate any recieved data - include the start of my layout - display results or error messages / warnings - include end of my layout There are loads of different ways to do it. Does anyone have a better method? Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343588 Share on other sites More sharing options...
slanton Posted September 7, 2007 Share Posted September 7, 2007 Instead of putting die('You did not complete all of the required fields'); you could put $error_message='You did not complete all of the required fields'; and the echo $error_message where ever you want. Is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343633 Share on other sites More sharing options...
seanpearman Posted September 7, 2007 Author Share Posted September 7, 2007 youre spot on with what I want to acheive, but the $error_message produces another issue, as the script submits the data to the database even if you leave all registration feilds blank. I know I can use validation, but the Die function stops accessing the db immediatley. I dont really want to play with the script, as it works fine, I just cant get my design in place. It would be great if I could do something like below, as my design is being included once a user signs up. it produces the message "Thank you, you have registered - you may now login" exactly where i want it, in the "content" part of the page, in my template/design. // now we insert it into the database $insert = "INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); include('../fmn/header.htm') ?> <p class="login_nav">Registered</p> <p class="login_nav">Thank you, you have registered - you may now login</a>.</p> <?php Quote Link to comment https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343661 Share on other sites More sharing options...
Aureole Posted September 7, 2007 Share Posted September 7, 2007 I think I get what you mean, here's an example to show you how you could do something like this... <?php // Do all your checking here...like for example if (empty($_POST['username'])) { die(); $error_message = "You didn't enter a Username."; } else { $username = mysql_real_escape_string($_POST['username']); } if(strlen($_POST['password']) < 5 ) { die(); $error_message = "Password not long enough..."; } else { $password = mysql_real_escape_string($_POST['password']); } // etc... if ($username && $password) { $insert... } else { echo('Errors: '.$error_message.''); // Show form again... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343666 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.