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
https://forums.phpfreaks.com/topic/92390-phpmysql-registration-form/
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.

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
}
?>

  • 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
}
}
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.