Jump to content

connect


ultratek

Recommended Posts

i am learning from a book on using databasing and registering users...

i cannot figure out why the registration wont work when i hit the register button

is there susposed to be a direct path to the database listed in the mysql connect?

 

this is the register page:

<?php
$page_title = 'Register';
include ('./includes/header.html');

if (isset($_POST['submitted'])) {
$errors = array();
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = trim($_POST['first_name']);
}
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = trim($_POST['first_name']);
}
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = trim($_POST['first_name']);
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = trim($_POST['password1']);
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
require_once ('mysql_connect.php');
$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
$result = @mysql_query ($query);
if ($result) {
echo '<h1 id="mainhead">Thank You!</h1>
<p>You are now registered. In chapter 9 you will actually be able to log in!</p><p>
<br /></p>';
include ('./includes/footer.html');
exit();
} else {
echo '<h1 id="mainhead">System Error</h1>
<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';
include ('./includes/footer.html');
exit();
}
mysql_close();
} else {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
}
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" maxlength="15" value="<?php if (isset($_POST['first_name'])) 
echo $_POST['first_name'];
?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) 
echo $_POST['last_name'];
?>" /></p>
<p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) 
echo $_POST['email'];
?>" /> </p>
<p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>

 

and this is the connect script:

<?php
DEFINE ('DB_USER', 'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
?>

Link to comment
https://forums.phpfreaks.com/topic/133134-connect/
Share on other sites

when it suscessfully registers it should say thankyou

 

And what does it say?

 

The first thing I would do is remove all instances of the error supressor ( @ ) from your function calls. Also if the book is telling you to put them there id throw that book out the window.

 

The next thing you need do is make sure error reporting is enabled and that php will display errors.

 

error_reporting(E_ALL) ; ini_set('display_errors','1');

Link to comment
https://forums.phpfreaks.com/topic/133134-connect/#findComment-692381
Share on other sites

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.