ultratek Posted November 17, 2008 Share Posted November 17, 2008 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 More sharing options...
trq Posted November 17, 2008 Share Posted November 17, 2008 is there susposed to be a direct path to the database listed in the mysql connect? No. Are you actually getting any errors? Link to comment https://forums.phpfreaks.com/topic/133134-connect/#findComment-692365 Share on other sites More sharing options...
ultratek Posted November 17, 2008 Author Share Posted November 17, 2008 well no errors.. its like it doesnt even connect... i am running apache and php and mysql all on my machine which are setup and working fine... when it suscessfully registers it should say thankyou Link to comment https://forums.phpfreaks.com/topic/133134-connect/#findComment-692372 Share on other sites More sharing options...
trq Posted November 17, 2008 Share Posted November 17, 2008 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 More sharing options...
ultratek Posted November 17, 2008 Author Share Posted November 17, 2008 it just reloads the register page but blank... i tried taking out the supressor and the dsiplay errors is on i even used what you gave me to turn them on.. i still get the blank register page... Link to comment https://forums.phpfreaks.com/topic/133134-connect/#findComment-692383 Share on other sites More sharing options...
flyhoney Posted November 17, 2008 Share Posted November 17, 2008 For what reason are you including an html file? include ('./includes/header.html'); Link to comment https://forums.phpfreaks.com/topic/133134-connect/#findComment-692387 Share on other sites More sharing options...
ultratek Posted November 17, 2008 Author Share Posted November 17, 2008 to load the header and footer once... i have used the include on all the pages as the book instructed... Link to comment https://forums.phpfreaks.com/topic/133134-connect/#findComment-692393 Share on other sites More sharing options...
flyhoney Posted November 18, 2008 Share Posted November 18, 2008 to load the header and footer once... i have used the include on all the pages as the book instructed... Never thought about using it that way Learn something new every day. Link to comment https://forums.phpfreaks.com/topic/133134-connect/#findComment-692415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.