DanielFrye
-
Posts
6 -
Joined
-
Last visited
Posts posted by DanielFrye
-
-
This is what my error log is currently telling me. Something on the password.php file.
[03-Sep-2014 09:29:28] PHP Parse error: syntax error, unexpected T_IF in /home4/fryemult/public_html/fryemultimedia/includes/lib/password.php on line 5
<?phpnamespace {if (!defined('PASSWORD_DEFAULT')) {define('PASSWORD_BCRYPT', 1);define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);/*** Hash the password using the specified algorithm** @param string $password The password to hash* @param int $algo The algorithm to use (Defined by PASSWORD_* constants)* @param array $options The options for the algorithm to use** @return string|false The hashed password, or false on error.*/function password_hash($password, $algo, array $options = array()) {if (!function_exists('crypt')) {trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);return null;}Everything on here is copied exactly. -
mysqli.inc.php
// Make the connection:$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);// Set the character set:mysqli_set_charset($dbc, 'utf8');// Function for escaping and trimming form data.// Takes one argument: the data to be treated (string).// Returns the treated data (string).function escape_data ($data, $dbc) {// Strip the slashes if Magic Quotes is on:if (get_magic_quotes_gpc()) $data = stripslashes($data);// Apply trim() and mysqli_real_escape_string():return mysqli_real_escape_string ($dbc, trim ($data));} // End of the escape_data() function.// Omit the closing PHP tag to avoid 'headers already sent' errors!The SQL for users-- phpMyAdmin SQL Dump-- version 3.5.8.2---- Host: localhost-- Generation Time: Sep 02, 2014 at 02:20 PM-- Server version: 5.5.38-35.2-log-- PHP Version: 5.4.23SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";SET time_zone = "+00:00";/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;DELIMITER $$---- Procedures--DROP PROCEDURE IF EXISTS `add_customer`$$$$DELIMITER ;-- ------------------------------------------------------------ Table structure for table `users`--DROP TABLE IF EXISTS `users`;CREATE TABLE IF NOT EXISTS `users` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,`type` enum('member','admin') NOT NULL DEFAULT 'member',`username` varchar(45) NOT NULL,`email` varchar(80) NOT NULL,`pass` varchar(255) NOT NULL,`first_name` varchar(45) NOT NULL,`last_name` varchar(45) NOT NULL,`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,`date_expires` date NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY `username_UNIQUE` (`username`),UNIQUE KEY `email_UNIQUE` (`email`),KEY `login` (`email`,`pass`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -
form_functions.inc.php
<?phpfunction create_form_input($name, $type, $label = '', $errors = array(), $options = array()) {// Assume no value already exists:$value = false;// Check for a value in POST:if (isset($_POST[$name])) $value = $_POST[$name];// Strip slashes if Magic Quotes is enabled:if ($value && get_magic_quotes_gpc()) $value = stripslashes($value);// Start the DIV:echo '<div class="form-group';// Add a class if an error exists:if (array_key_exists($name, $errors)) echo ' has-error';// Complete the DIV:echo '">';// Create the LABEL, if one was provided:if (!empty($label)) echo '<label for="' . $name . '" class="control-label">' . $label . '</label>';// Conditional to determine what kind of element to create:if ( ($type === 'text') || ($type === 'password') || ($type === 'email')) {// Start creating the input:echo '<input type="' . $type . '" name="' . $name . '" id="' . $name . '" class="form-control"';// Add the value to the input:if ($value) echo ' value="' . htmlspecialchars($value) . '"';// Check for additional options:if (!empty($options) && is_array($options)) {foreach ($options as $k => $v) {echo " $k=\"$v\"";}}// Complete the element:echo '>';// Show the error message, if one exists:if (array_key_exists($name, $errors)) echo '<span class="help-block">' . $errors[$name] . '</span>';} elseif ($type === 'textarea') { // Create a TEXTAREA.// Show the error message above the textarea (if one exists):if (array_key_exists($name, $errors)) echo '<span class="help-block">' . $errors[$name] . '</span>';// Start creating the textarea:echo '<textarea name="' . $name . '" id="' . $name . '" class="form-control"';// Check for additional options:if (!empty($options) && is_array($options)) {foreach ($options as $k => $v) {echo " $k=\"$v\"";}}// Complete the opening tag:echo '>';// Add the value to the textarea:if ($value) echo $value;// Complete the textarea:echo '</textarea>';} // End of primary IF-ELSE.// Complete the DIV:echo '</div>';} -
Sorry for the late replies as I have gotten busy on another site that popped up. I've spent a couple days here again trying to fix this issue, but I'm still getting blank pages when registering.
Register.php
<?phprequire('./includes/config.inc.php');require(MYSQL);$page_title = 'Register';include('./includes/header.html');$reg_errors = array();if ($_SERVER['REQUEST_METHOD'] === 'POST') {// Check for a first name:if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['first_name'])) {$fn = escape_data($_POST['first_name'], $dbc);} else {$reg_errors['first_name'] = 'Please enter your first name!';}// Check for a last name:if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['last_name'])) {$ln = escape_data($_POST['last_name'], $dbc);} else {$reg_errors['last_name'] = 'Pleaes enter your last name';}// Check for a username:if (preg_match('/^[A-Z0-9]{2,45}$/i', $_POST['username'])) {$u = escape_data($_POST['username'], $dbc);} else {$reg_errors['username'] = 'Please enter a desired name using only letters and numbers!';}// Check for an email address:if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === $_POST['email']) {$e = escape_data($_POST['email'], $dbc);} else {$reg_errors['email'] = 'Please enter a valid email address!';}// Check for a password and match against the confirmed password:if (preg_match('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,}$/', $_POST['pass1']) ) {if ($_POST['pass1'] === $_POST['pass2']) {$p = $_POST['pass1'];} else {$reg_errors['pass2'] = 'Your password did not match the confirmed password!';}} else {$reg_errors['pass1'] = 'Please enter a valid password!';}if (empty($reg_errors)) {$q = "SELECT email, username FROM users WHERE email='$e' OR username='$u'";$r = mysqli_query($dbc, $q);$rows = mysqli_num_rows($r);if ($rows === 0) {include('./includes/lib/password.php');$q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 12 MONTH) )";$r = mysqli_query($dbc, $q);if (mysqli_affected_rows($dbc) === 1) {echo '<div class="alert alert-success"><h3>Thanks!</h3><p>Thank you for registering!</p></div>';$body = "Thank you for registering with Summit Learning and Technologies";mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@summitlt.com');include('./includes/footer.html');exit();} else {trigger_error('You could not be registered due to a system error. We apologize for any inconvenience. We will correct the error ASAP.');}if ($rows === 2) {$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the left to have your password sent to you.';$reg_errors['username'] = 'This username has already been registered. Please try another.';} else {$row = mysqli_fetch_array($r, MYSQLI_NUM);if( ($row[0] === $_POST['email']) && ($row[1] === $_POST['username'])) {$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.';$reg_errors['username'] = 'This username has already been registered with this email address. If you have forgotten your password, use the link at left to have your password sent to you.';} elseif ($row[0] === $_POST['email']) {$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.';} elseif ($row[1] === $_POST['username']) {$reg_errors['username'] = 'This username has already been registered. Please try another.';}}}}}?><h1>Register</h1><form action="register.php" method="post" accept-charset="utf-8"><?phpcreate_form_input('first_name', 'text', 'First Name', $reg_errors);create_form_input('last_name', 'text', 'Last Name', $reg_errors);create_form_input('username', 'text', 'Desired Username', $reg_errors);echo '<span class="help-block">Only letters and numbers are allowed.</span>';create_form_input('email', 'email', 'Email Address', $reg_errors);create_form_input('pass1', 'password', 'Password', $reg_errors);echo '<span class="help-block">Must be at least 6 characters long, with at least one lowercase letter, one uppercase letter, and one number.</span>';create_form_input('pass2', 'password', 'Confirm Password', $reg_errors);?><input type="submit" name="submit_button" value="Next →" id="submit_button" class="btn btn-default" /></form><br><?php // Include the HTML footer:include('./includes/footer.html');?> -
Buckeye,
It's been a couple months, but I was wondering if you could elaborate some on what your fix was. I am currently experiencing the same issue as you were when you made the post.
Thank You
Registration Page Example 1
in Effortless E-Commerce with PHP and MySQL (2nd Edition)
Posted
Thank you for the reply.. It's version PHP Version: 5.4.23