Jump to content

PHP/MYSQL Registration Form


edah527

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

  • 3 weeks later...

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.