im trying to teach myself php. I've put together a simple login script. Im making the registration page now. Theres an error i dont recognize. If you see any other problems please tell me about them to. error: my code: <?php //get form info $firstname=$_POST["firstname"]; $lastname=$_POST["lastname"]; $username=$_POST["username"]; $password=$_POST["password"]; $confirmppassword=$_POST["confirmpassword"]; $emailaddress=$_POST["emailaddress"]; $secretquestion=$_POST["secretquestion"]; $secretanswer=$_POST["secretanswer"]; //make variables some encrypt $cpass = md5($password); $cuser = md5($username); $csecretanswer = md5($secretanswer); $file = "users/" . $user . ".php"; $data = "<?php $cpass=" . $cpass . "; $cuser=" . $cuser . "; $firstname=" . $firstname . "; $lastname=" . $lastname . "; $secretquestion=" . $secretquestion . "; $csecretanswer=" . $csecretanswer . " ?> //make sure all info is ok if ($password!=$confirmpassword) { echo "Your password do not match. <a href="register2.htm">Try Again</a><br>; exit(0); } if (file_exists($file)) { echo "Username is in use. <a href="register2.htm">Try Again</a><br>; exit(0); } //make users file $handle = fopen($file); fwrite($handle, $data); fclose($handle); head ( 'location: index.htm' ); ?> PHP: thanks for any help.
Your strings are not closed. You should use single quotes to define string containing double quotes: echo 'Your password do not match. <a href="register2.htm">Try Again</a><br>'; PHP: or escape quotes: echo "Your password do not match. <a href=\"register2.htm\">Try Again</a><br>"; PHP:
Is it really so hard to read the error line number, go to that line and correct the error? Your $data declaration contains unterminated string and missing semicolon too. Fixed code: <?php //get form info $firstname=$_POST["firstname"]; $lastname=$_POST["lastname"]; $username=$_POST["username"]; $password=$_POST["password"]; $confirmppassword=$_POST["confirmpassword"]; $emailaddress=$_POST["emailaddress"]; $secretquestion=$_POST["secretquestion"]; $secretanswer=$_POST["secretanswer"]; //make variables some encrypt $cpass = md5($password); $cuser = md5($username); $csecretanswer = md5($secretanswer); $file = "users/" . $user . ".php"; $data = "<?php $cpass=" . $cpass . "; $cuser=" . $cuser . "; $firstname=" . $firstname . "; $lastname=" . $lastname . "; $secretquestion=" . $secretquestion . "; $csecretanswer=" . $csecretanswer . " ?>"; //make sure all info is ok if ($password!=$confirmpassword) { echo 'Your password do not match. <a href="register2.htm">Try Again</a><br>'; exit(0); } if (file_exists($file)) { echo 'Username is in use. <a href="register2.htm">Try Again</a><br>'; exit(0); } //make users file $handle = fopen($file); fwrite($handle, $data); fclose($handle); head ( 'location: index.htm' ); ?> PHP: