futurewii Posted February 12, 2009 Share Posted February 12, 2009 Ok so this is my script.. well its one of the net.. its a registration form which only came with two fields to regitser, $user and $pass. (which i changed the $username and $password).. i added some other fields and when completed i got the syntax error.. i didnt test it before so dont know whether its my shoddy scripting or what.. any help much appreciated (Its line 89), which says - die('You didn't fill in a required field'); <? session_start(); include("includes/conn.php"); /** * Returns true if the username has been taken * by another user, false otherwise. */ function usernameTaken($username){ global $conn; if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0); } /** * Inserts the given (username, password) pair * into the database. Returns true on success, * false otherwise. */ function addNewUser($fullname, $username, $password, $dob, $email, $country){ global $conn; $q = "INSERT INTO users VALUES ('$fullname', '$username', '$password', '$dob', '$email', '$country')"; return mysql_query($q,$conn); } /** * Displays the appropriate message to the user * after the registration attempt. It displays a * success or failure status depending on a * session variable set during registration. */ function displayStatus(){ $uname = $_SESSION['reguname']; if($_SESSION['regresult']){ ?> <h1>Registered!</h1> <p>Thank you <? echo $username; ?>, your information has been added to the database, you may now <a href="?page=login" title="Login">log in</a>!</p> <? } else{ ?> <h1>Registration Failed </h1> <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $username; ?></b>, could not be completed.<br> Please try again at a later time.</p> <? } unset($_SESSION['reguname']); unset($_SESSION['registered']); unset($_SESSION['regresult']); } if(isset($_SESSION['registered'])){ /** * This is the page that will be displayed after the * registration has been attempted. */ ?> <html> <title>Registration Page</title> <body> <? displayStatus(); ?> </body> </html> <? return; } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ if(isset($_POST['subjoin'])){ /* Make sure all fields were entered */ if(!$_POST['fullname'] || !$_POST['username'] || !$_POST['password'] || !$_POST['dob'] || !$_POST['email'] || !$_POST['country']) { die('You didn't fill in a required field'); } /* Spruce up username, check length */ $_POST['username'] = trim($_POST['username']); if(strlen($_POST['username']) > 30) { die("Sorry, the username is longer than 30 characters, please shorten it."); } /* Check if username is already in use */ if(usernameTaken($_POST['username'])){ $use = $_POST['username']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } /* Add the new account to the database */ $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['username'], $md5pass); $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[php_SELF]\">"; return; } else{ /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Registration Page</title> <body> <h1>Register</h1> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr> </table> </form> </body> </html> <? } ?> Link to comment https://forums.phpfreaks.com/topic/144953-parse-error-syntax-error-unexpected-t_string-grateful-for-any-help/ Share on other sites More sharing options...
premiso Posted February 12, 2009 Share Posted February 12, 2009 die('You didn\'t fill in a required field'); Single quote was not escaped. Link to comment https://forums.phpfreaks.com/topic/144953-parse-error-syntax-error-unexpected-t_string-grateful-for-any-help/#findComment-760634 Share on other sites More sharing options...
ratcateme Posted February 12, 2009 Share Posted February 12, 2009 you need to escape the ' in didn't beaten to it Scott. Link to comment https://forums.phpfreaks.com/topic/144953-parse-error-syntax-error-unexpected-t_string-grateful-for-any-help/#findComment-760635 Share on other sites More sharing options...
futurewii Posted February 12, 2009 Author Share Posted February 12, 2009 Thank you very much you two Link to comment https://forums.phpfreaks.com/topic/144953-parse-error-syntax-error-unexpected-t_string-grateful-for-any-help/#findComment-760665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.