wizzy886 Posted October 19, 2013 Share Posted October 19, 2013 Here is the code for both the connection file and the main body of script. I assure you the passwords and actual names do match as I have done other tests before hand. register.php <?php $title = "Register"; include 'includes/header.php'; if($_SERVER['REQUEST_METHOD'] == 'POST') { require 'includes/connection.php'; //create FALSE figures $username = $password = FALSE; //trim all data $trimmed = array_map('trim', $_POST); $errors = array(); //check username if(preg_match ('/[A-Za-z0-9]{2,20}/', $trimmed['username'])) { $username = mysqli_real_escape_string($dbc, $trimmed['username']); } else { $errors[] = 'Enter a username'; } //check password if(preg_match ('/[A-Za-z0-9]{4,20}/', $trimmed['password'])) { $username = mysqli_real_escape_string($dbc, $trimmed['password']); } else { $errors[] = 'Enter a password'; } //variables not == FALSE if($username && $password) { $q = "SELECT user_id FROM users WHERE username='$username'"; $r = mysqli_query ($dbc, $q) OR trigger_error("Query: $q\n<br />MYSQL Error: ". mysql_error($dbc)); if(mysqli_num_rows($r) == 0) { $q = "INSERT INTO users (username, password, registration_date) VALUES ('$username', SHA1('$password'), NOW() )"; $r = mysqli_query ($dbc, $q) OR trigger_error("Query: $q\n<br />MYSQL Error: ". mysql_error($dbc)); } if(mysqli_affected_rows($dbc) == 1) { echo "success"; //header('Location: database.php'); } } else { foreach ($errors as $msg) { echo " - $msg<br />\n"; } } } ?> <form action="register.php" method="POST"> <input type="text" name="username" value="<?php if(isset($trimmed['username'])) echo $trimmed['username']; ?>" placeholder="Username"/> <input type="password" name="password" value="<?php if(isset($trimmed['username'])) echo $trimmed['password']; ?>" placeholder="Password"/> <input type="submit" class="button1" name="Sign Up" /> </form> connection.php <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $db = 'ze'; $dbc = mysqli_connect($dbhost, $dbuser, $dbpass) OR die ('Could not connect. MYSQL:' .mysql_error() ); mysql_select_db($db); Whenever I run this it does not seem to want to work, and also outputs no errors. I probably cant see something and need a second opinion. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 19, 2013 Share Posted October 19, 2013 it does not seem to want to work In what way does it not want to work? Quote Link to comment Share on other sites More sharing options...
wizzy886 Posted October 19, 2013 Author Share Posted October 19, 2013 No errors are displayed and no records are entered. I cannot really say much more as its not even displaying errors. So I'm of the impression it might be how I've structured it or something? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 19, 2013 Share Posted October 19, 2013 mysql_select_db($db); you are using mysqli Quote Link to comment Share on other sites More sharing options...
wizzy886 Posted October 19, 2013 Author Share Posted October 19, 2013 Ahh yes thanks. However I still think its not working. Any other ideas? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 19, 2013 Share Posted October 19, 2013 Think? Have you not tested it? Quote Link to comment Share on other sites More sharing options...
wizzy886 Posted October 19, 2013 Author Share Posted October 19, 2013 Sorry I mean to say that by what I can still see after that change its still not working. Quote Link to comment Share on other sites More sharing options...
wizzy886 Posted October 19, 2013 Author Share Posted October 19, 2013 Have I used the preg_match properly?? As I have wondered if its actually working properly. Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 19, 2013 Solution Share Posted October 19, 2013 $username = mysqli_real_escape_string($dbc, $trimmed['password']); ??? Quote Link to comment Share on other sites More sharing options...
wizzy886 Posted October 19, 2013 Author Share Posted October 19, 2013 That's the problem when you copy and paste and don't pay attention. I think I will learn from that. Thanks for your time as its now working. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 19, 2013 Share Posted October 19, 2013 I probably cant see something and need a second opinion. Yep, a second pair of eyes often helps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.