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] Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/ 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.... , Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/#findComment-473341 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. Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/#findComment-473382 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 } ?> Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/#findComment-474181 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>"; Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/#findComment-474200 Share on other sites More sharing options...
edah527 Posted March 10, 2008 Author Share Posted March 10, 2008 didnt help Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/#findComment-488163 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 } } ?> Link to comment https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/#findComment-488471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.