Snooble Posted March 5, 2007 Share Posted March 5, 2007 I have 2 pages, register.php, checkregister.php. in register i thought i would (before each form textfield) place an if statement. Which looks like this: (I have the includes at the top of the page to start session... <?php if(isset($_SESSION['usernamereg'])){ echo 'Please Eneter A Username:<input name="username" type="text" id="username" size="10" maxlength="10" value="'.$_SESSION['usernamereg'].'/>'; } else { echo '<input name="username" type="text" id="username" size="10" maxlength="10"/>'; } ?> On check register i have this: <?php include 'expire.php'; include 'sessionstartandsql.php'; $_POST['username'] = $_SESSION['usernamereg']; $_POST['password'] = $_SESSION['passwordreg']; $_POST['email'] = $_SESSION['emailreg']; if ($_POST['username'] == NULL){ header("Location: register.php");} if ($_POST['password'] == NULL){ header("Location: register.php");} if ($_POST['email'] == NULL){ header("Location: register.php");} $sql = "INSERT INTO wmusers VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0', '0', '0')"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); ?> Any help? At the moment i get taken to the register page but i ALWAYS get the textfield without anything in it and without the "Please Eneter A Username:" bit echo'd. There must be something wrong with the register page i think. Snooble (Thanks in advance) Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/ Share on other sites More sharing options...
redarrow Posted March 5, 2007 Share Posted March 5, 2007 session_start() needs to be placed on all pages not as an included file ok? Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199844 Share on other sites More sharing options...
Snooble Posted March 5, 2007 Author Share Posted March 5, 2007 noway? an included file is completly pasted into the doc? I thought it was? Ok i'll give it a go, ta Snooble Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199854 Share on other sites More sharing options...
Snooble Posted March 5, 2007 Author Share Posted March 5, 2007 same problem. Snooble Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199857 Share on other sites More sharing options...
redarrow Posted March 5, 2007 Share Posted March 5, 2007 why are you postting twice post once? Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199860 Share on other sites More sharing options...
Greaser9780 Posted March 5, 2007 Share Posted March 5, 2007 Maybe you didn't show it. The register code you showed doesn't prompt for an email. But in your check page you tell it to redirect to register if no email was post. Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199863 Share on other sites More sharing options...
superuser2 Posted March 5, 2007 Share Posted March 5, 2007 I don't think session start is your problem... Your logic is backwards. <?php ... $_POST['username'] = $_SESSION['usernamereg']; $_POST['password'] = $_SESSION['passwordreg']; $_POST['email'] = $_SESSION['emailreg']; should be <?php $_SESSION['usernamereg'] = $_POST['username']; $_SESSION['passwordreg'] = $_POST['password']; $_SESSION['emailreg'] = $_POST['email']; <?php if(isset($_SESSION['usernamereg'])){ is always going to be true, no matter what. $_SESSION['usernamereg'] will be set, even if it's empty. Also, don't you want to display this only if it's empty?!? So you need to check if there's a value: <?php if(strlen($_SESSION['usernamereg']) < 1) { That will check to make sure it's empty. I don't know if it will work, but try it and let us know what happens. Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199864 Share on other sites More sharing options...
Snooble Posted March 5, 2007 Author Share Posted March 5, 2007 thank you, i dont know where i got isset from :?. Thank you, I double posted because otherwise you may of thought it was fixed. an exit doesn't bring the topic to the top does it? Anyway, thank you very much for that, Snoobs Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199874 Share on other sites More sharing options...
superuser2 Posted March 5, 2007 Share Posted March 5, 2007 So is everything working now? If so, click the 'Topic Solved' button/link and this thread will be marked solved. Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199876 Share on other sites More sharing options...
Snooble Posted March 5, 2007 Author Share Posted March 5, 2007 i know how the topic solved button works, thank you. Will check when i can. Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199901 Share on other sites More sharing options...
Snooble Posted March 6, 2007 Author Share Posted March 6, 2007 <?php if(strlen($_SESSION['usernamereg']) < 1) { thanks for that... it was causing a syntax error. Took me bloody ages lol. <?php if(strlen($_SESSION['usernamereg'] < 1)) { ^ Correct way Snooble Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-200826 Share on other sites More sharing options...
superuser2 Posted March 6, 2007 Share Posted March 6, 2007 Wait, mine was causing a syntax error? The code samples you posted are the same. Link to comment https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-201112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.