I took a look at this posted question: I am getting no errors but the data is not going into the database on wamp but I did use mysqli for my code.
Here is my code:
<?php
include( "includes/header.php" );
error_reporting(E_ALL); ini_set('display_errors', '1');
$register = $_POST['register'];
//declaring variables needed for the registration form to prevent errors
$fname = "";
$lname = "";
$uname = "";
$email = "";
$email2 = "";
$password = "";
$password2 = "";
$signup_date = "";
$username_check = ""; // check if username exists
//assigning variables from the registration form
$fname = strip_tags($_POST['fname']);
$lname = strip_tags($_POST['lname']);
$uname = strip_tags($_POST['uname']);
$email = strip_tags($_POST['email']);
$email2 = strip_tags($_POST['email2']);
$password = strip_tags($_POST['password']);
$password2 = strip_tags($_POST['password2']);
$signup_date = date("Y-m-d");
if ($register) {
if ($email == $email2) {
$username_check = mysqli_query("SELECT username FROM users WHERE username = '$uname'");
$row = mysqli_num_rows($username_check);
if ($row == 0) {
if ($fname&&$lname&&$uname&&$email&&$email2&&$password&&$password2) {
if ($password == $password2) {
if (strlen($uname)>25||strlen($fname)>25||strlen($lname)>25) {
echo "The maximum limit for username/first name/ last name is 25 characters!";
} elseif (strlen($password)>30||strlen($password)<5) {
echo "Your password must be between 5 and 30 characters long!";
} else {
$password = password_hash($password);
$password2 = password_hash($password2);
$query = mysqli_query('INSERT INTO users VALUES ("","$uname","$fname","$lname","$email","$password","$signup_date","0")');
die("<h2>Welcome to HackerBits</h2>Login to your account to get started . . . ");
}
} else {
echo "Your passwords don't match!";
}
} else {
echo "Please fill in all of the fields.";
}
} else {
echo "Username already taken . . . ";
}
} else {
echo "Your emails don't match!";
}
}
?>
I know it is messy, I am new to php, only 1 week in. So like I said it goes to the die("<h2>Welcome to HackerBits</h2>Login to your account to get started . . . ");
part of the code with no errors. Then when I go to my database the user is not in the table. Which means I can then go back to the registration form and put in the same values.
Sorry if this is a bad question, new to stakeoverflow, just tell me and I will fix it up :) I can also give you more info if needed. I am using MAMP by the way.
I connect to the database with the included script:
<?php
$db = new mysqli('mysql:host=localhost;dbname=users_table', 'root', 'taken-out');
?>
Errors given:
Warning: mysqli_query() expects at least 2 parameters, 1 given in /Users/darceymckelvey/Desktop/php/social_network/index.php on line 27
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Users/darceymckelvey/Desktop/php/social_network/index.php on line 28
Warning: password_hash() expects at least 2 parameters, 1 given in /Users/darceymckelvey/Desktop/php/social_network/index.php on line 37
Warning: password_hash() expects at least 2 parameters, 1 given in /Users/darceymckelvey/Desktop/php/social_network/index.php on line 38
Warning: mysqli_query() expects at least 2 parameters, 1 given in /Users/darceymckelvey/Desktop/php/social_network/index.php on line 39
They are all warnings which I don't think are fatal because it still executes the code to display the login message.
I have tried these lines:
$username_check = mysqli_query($db, "SELECT username FROM users WHERE username = '$uname'");
but same warnings.
"; die(); }"* - that's even worse. You're mixing MySQLi_ and PDO APIs. – Funk Forty Niner May 02 '16 at 01:22