Flowdy Posted November 23, 2007 Share Posted November 23, 2007 This is the first time ive tried to code anything, A registration form...but it doesnt seem to work First the HTML <html> <head> <include ="registration.php"> <body> <form> <p>Name:<br> <input type="text" size="20"><br> <p>Email Address:<br> <input type="text" size="20"><br> <p>Username:<br> <input type="text" size="20"><br> <p>Password:<br> <input type="password" size="20"><br> <p>Verify Password:<br> <input type="password" size="20"><br> <br> <input type="Submit" value="Submit"> </form> </body> </html> now the PHP <?php /* Has user submitted data? If not, display the registration form. */ if (! isset($_POST['submitbutton'])) { echo file_get_contents("/templates/register.html"); /* Form data has been submitted. */ } else { $conn = mysql_pconnect("localhost", "corpweb", "secret"); mysql_select_db("mygame"); /* Ensure that the password and password verifier match. */ if ($_POST['pswd'] != $_POST['pswdagain']) { echo "<p>The passwords do not match. Please go back and try again.</p>"; /* Passwords match, attempt to inster information into userauth table. */ } else { try { $_query ="INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$_POST[name]', '$_POST[email]', '$_POST[username]', md5('$_POST[pswd]')); $result = mysql_query($query); if (! $result) { throw new Exception( "Registration problems were encountered!" ); } else { echo "<p>Registration was sucessful!</p>; } } catch(Exception $e) { echo "<p>".$e->getMessage()."</p>"; } #endCatch } } ?> Thanx for any help given Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 23, 2007 Share Posted November 23, 2007 whats the error message ? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 23, 2007 Share Posted November 23, 2007 <include ="registration.php"> I've never seen that used before lol. You need to POST the data to your PHP script, where you have <form> change it to this: <form name="registration" method="post" action="url to your PHP script"> Quote Link to comment Share on other sites More sharing options...
Flowdy Posted November 24, 2007 Author Share Posted November 24, 2007 okies i changed that now i get this error when clicking submit Parse error: syntax error, unexpected '{' in /home/poison/public_html/testphp/registration.php on line 24 Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 24, 2007 Share Posted November 24, 2007 where is that line??? or rather your new code Quote Link to comment Share on other sites More sharing options...
trq Posted November 24, 2007 Share Posted November 24, 2007 $_query ="INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$_POST[name]', '$_POST[email]', '$_POST[username]', md5('$_POST[pswd]')); needs to be.... $_query ="INSERT INTO userauth (commonname, email, username, pswd) VALUES ('{$_POST['name']}', '{$_POST['email']}', '{$_POST['username']}','" . md5($_POST['pswd']) . "'"; Quote Link to comment Share on other sites More sharing options...
Flowdy Posted November 24, 2007 Author Share Posted November 24, 2007 I changed that to that but im still getting the exact same error msg Quote Link to comment Share on other sites More sharing options...
trq Posted November 24, 2007 Share Posted November 24, 2007 Can you post your current code. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 24, 2007 Share Posted November 24, 2007 Post your new code please. Quote Link to comment Share on other sites More sharing options...
Flowdy Posted November 24, 2007 Author Share Posted November 24, 2007 Sorry here is the updated code <?php /* Has user submitted data? If not, display the registration form. */ if (! isset($_POST['submitbutton'])) { echo file_get_contents("/templates/register.html"); /* Form data has been submitted. */ } else { $conn = mysql_pconnect("localhost", "corpweb", "secret"); mysql_select_db("mygame"); /* Ensure that the password and password verifier match. */ if ($_POST['pswd'] != $_POST['pswdagain']) { echo "<p>The passwords do not match. Please go back and try again.</p>"; /* Passwords match, attempt to inster information into userauth table. */ } else { try { $_query ="INSERT INTO userauth (commonname, email, username, pswd) VALUES ('{$_POST['name']}', '{$_POST['email']}', '{$_POST['username']}','" . md5($_POST['pswd']) . "'"; $result = mysql_query($query); if (! $result) { throw new Exception( "Registration problems were encountered!" ); } else { echo "<p>Registration was sucessful!</p>; } } catch(Exception $e) { echo "<p>".$e->getMessage()."</p>"; } #endCatch } } ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 24, 2007 Share Posted November 24, 2007 What version of PHP do you have installed? I see you're using try/catch statements these are only available with PHP5. PHP4 does not support these. Also line 34 should be: echo "<p>Registration was sucessful!</p>"; You forgot the " at the end of the line to close the string. Quote Link to comment Share on other sites More sharing options...
Flowdy Posted November 24, 2007 Author Share Posted November 24, 2007 That could be why... According to this http://www.testphp.poison-envy.net/infophp.php i have php 4.4.7 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 24, 2007 Share Posted November 24, 2007 You'll have to remove the try/catch statement then and use basic if/else statements instead: <?php /* Has user submitted data? If not, display the registration form. */ if (! isset($_POST['submitbutton'])) { echo file_get_contents("/templates/register.html"); /* Form data has been submitted. */ } else { $conn = mysql_pconnect("localhost", "corpweb", "secret"); mysql_select_db("mygame"); /* Ensure that the password and password verifier match. */ if ($_POST['pswd'] != $_POST['pswdagain']) { echo "<p>The passwords do not match. Please go back and try again.</p>"; /* Passwords match, attempt to inster information into userauth table. */ } else { // never use raw _POST data within a query. Always escape user input. // I suggest using mysql_real_escape_string to help prevent SQL Injection attacks. $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $query = 'INSERT INTO userauth (commonname, email, username, pswd) '; $query .= "VALUES ('$name', '$email', '$username','" . md5($_POST['pswd']) . "'"; $result = mysql_query($query) or die('Registration problems were encountered!'); echo "<p>Registration was sucessful!</p>"; } } ?> That code should work as expected. Note I added a bit of extra code to help prevent SQL Injection attacks. Quote Link to comment Share on other sites More sharing options...
Flowdy Posted November 24, 2007 Author Share Posted November 24, 2007 Thanx for that now am getting an error on line 9 am guessing its this part echo file_get_contents("/templates/register.html"); as its were your file is stored right..and mine isnt stored in /templates/ mine is in /home/poison/public_html/testphp/register.html but when i put that in i still get the same error msg Warning: file_get_contents(home/poison/public_html/testphp/register.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/poison/public_html/testphp/registration.php on line 9 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 24, 2007 Share Posted November 24, 2007 I've not modified that part of the code. However I believe it should be: echo file_get_contents("./templates/register.html"); Quote Link to comment Share on other sites More sharing options...
Flowdy Posted November 24, 2007 Author Share Posted November 24, 2007 I'm still getting the same error msg Warning: file_get_contents(/templates/register.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/poison/public_html/testphp/registration.php on line 9 This is going to sound stupid but is it cos i havent got a connect.php? 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.