edah527 Posted February 22, 2008 Share Posted February 22, 2008 K ive done this so many times and i cant seem to get it right... can some1 sell me whats wrong with this script plz??? [pre]<?php if (! isset($_POST["submit"])) { echo file_get_contents("C:\xampp\htdocs\register.html"); } else { $mysqli=mysqli_connect("localhost", "mysqluser1", "", "users"); if ($_POST["password"] != $_POST["password2"]) { echo "<p>The passwords don't match. Go back and try again.</p>"; } else { $query="INSERT INTO authusers ('first', 'last', 'email', 'username', 'password') VALUES ('$_POST[first]', '$_POST[last]', '$_POST', '$_POST[username]', '$_POST[password]');"; $result=mysqli_query($mysqli, $query); if (! $result) { throw new Exception( "Registration problems were encountered!" ); } else { echo "<p>Registration was succussful!</p>"; } } catch(Exception $e) { echo "<p>".$e->getMessage(),"</p>"; } #endCatch } ?>[/pre] Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 22, 2008 Share Posted February 22, 2008 please wrap you code in [ code ] tags. much easier to read. try to explain your problem a little bit instead of just saying ahhh its broke...fix it.... , Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted February 22, 2008 Share Posted February 22, 2008 Also it helps if you post the error you are receiving. From just looking at the code, here is what l see that needs to be fixed. <?php echo "<p>".$e->getMessage(),"</p>"; // To echo "<p>".$e->getMessage()."</p>"; ?> Can't really help you more until you give the exact error that is happening. Quote Link to comment Share on other sites More sharing options...
edah527 Posted February 23, 2008 Author Share Posted February 23, 2008 srry bout that... this is the error message: Parse error: syntax error, unexpected T_CATCH in C:\xampp\htdocs\registerfinished.php on line 18 This is the script again: <?php if (! isset($_POST["submit"])) { echo file_get_contents("C:\xampp\htdocs\register.html"); } else { $mysqli=mysqli_connect("localhost", "mysqluser1", "", "users"); if ($_POST["password"] != $_POST["password2"]) { echo "<p>The passwords don't match. Go back and try again.</p>"; } else { $query="INSERT INTO authusers ('first', 'last', 'email', 'username', 'password') VALUES ('$_POST[first]', '$_POST[last]', '$_POST[email]', '$_POST[username]', '$_POST[password]');"; $result=mysqli_query($mysqli, $query); if (! $result) { throw new Exception( "Registration problems were encountered!" ); } else { echo "<p>Registration was succussful!</p>"; } } catch(Exception $e) { echo "<p>".$e->getMessage(),"</p>"; } #endCatch } ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted February 23, 2008 Share Posted February 23, 2008 AS dual_alliance said: change this line echo "<p>".$e->getMessage(),"</p>"; to: echo "<p>".$e->getMessage()."</p>"; Quote Link to comment Share on other sites More sharing options...
edah527 Posted March 10, 2008 Author Share Posted March 10, 2008 didnt help Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 10, 2008 Share Posted March 10, 2008 never used exception handling but i know you need a try { // function } catch(...){ // exception } try this code: <?php function checkresult($result){ if (! $result) { throw new Exception("Registration problems were encountered!"); } else { echo "<p>Registration was succussful!</p>"; } } if (! isset($_POST["submit"])) { echo file_get_contents("C:\xampp\htdocs\register.html"); } else { $mysqli=mysqli_connect("localhost", "mysqluser1", "", "users"); if ($_POST["password"] != $_POST["password2"]) { echo "<p>The passwords don't match. Go back and try again.</p>"; } else { $query="INSERT INTO authusers ('first', 'last', 'email', 'username', 'password') VALUES ('$_POST[first]', '$_POST[last]', '$_POST[email]', '$_POST[username]', '$_POST[password]');"; $result=mysqli_query($mysqli, $query); // try THEN catch. try { checkresult ($result); } catch(Exception $e) { echo "<p>".$e->getMessage(),"</p>"; } #endCatch } } ?> 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.