Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,908,571 members, 7,014,544 topics. Date: Saturday, 13 August 2022 at 06:58 AM

I'm Having An Issue With My Php User Registration - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / I'm Having An Issue With My Php User Registration (688 Views)

Adsense Placement On My Php Site / Help Oo I Dont Know Wots Renaming My Php Files On My Namecheap Server / Download All My Php/website Scripts With Just A Token (2) (3) (4)

(1) (Reply) (Go Down)

I'm Having An Issue With My Php User Registration by funkmrflexx(m): 9:09pm On Feb 27, 2020
I created a user registration system with php. I ran it on my local host and it worked as expected but as soon as I uploaded the website to a hosting account it refused to store user information in my hosting account data base.

I already change d server informations from local host to the database on my hosting account. I need suggestions

below is the code

<?php
session_start();

// variable declaration
$name = "";
$username = "";
$email = "";
$number = "";
$address = "";
$zipcode = "";
$errors = array();
$_SESSION['success'] = "";

// connect to database
$db = mysqli_connect('localhost:3306','prakopwg_goodwill','bugatti','prakopwg_bank');

// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form

$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$number = mysqli_real_escape_string($db, $_POST['number']);
$address = mysqli_real_escape_string($db, $_POST['address']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);

// form validation: ensure that the form is correctly filled

if (empty($username)) { array_push($errors, "Username is required"wink; }
if (empty($email)) { array_push($errors, "Email is required"wink; }
if (empty($number)) { array_push($errors, "Phone Number is required"wink; }
if (empty($address)) { array_push($errors, "Your Address is required"wink; }

if (empty($password_1)) { array_push($errors, "Password is required"wink; }

if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match"wink;
}

// register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password_1);//encrypt the password before saving in the database
$query = "INSERT INTO customer ( name, username, email, number, address, zipcode, password)
VALUES( '$name','$username', '$email', '$number','address', 'zipcode', '$password')";
mysqli_query($db, $query);

$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}

}

// ...

// LOGIN USER
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($username)) {
array_push($errors, "Username is required"wink;
}
if (empty($password)) {
array_push($errors, "Password is required"wink;
}

if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM customer WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}else {
array_push($errors, "Wrong username/password combination"wink;
}
}
}

?>





i keep getting these errors


Warning: mysqli_connect(): (HY000/1045): Access denied for user 'prakopwg_goodwill'@'localhost' (using password: YES) in C:\xampp\htdocs\Tor\server.php on line 15

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\Tor\server.php on line 21
Re: I'm Having An Issue With My Php User Registration by resosdigital(m): 9:22pm On Feb 27, 2020
Post details of your error or code l
Re: I'm Having An Issue With My Php User Registration by ellagabs(f): 11:18pm On Feb 27, 2020
screen shot or paste the error code here Sir
Re: I'm Having An Issue With My Php User Registration by funkmrflexx(m): 4:20am On Feb 28, 2020
ellagabs:
screen shot or paste the error code here Sir

i posted the code please check it out
Re: I'm Having An Issue With My Php User Registration by funkmrflexx(m): 4:21am On Feb 28, 2020
resosdigital:
Post details of your error or code l

i posted the code please check it out
Re: I'm Having An Issue With My Php User Registration by niel63(m): 4:48am On Feb 28, 2020
Likely causes of these errors are:

1. Permission issue
2. Wrong/Invalid credentials

Double check your files, make sure there aren't whitespace on the credentials input during migration. Also, confirm you aren't making common mistakes of typo.
Re: I'm Having An Issue With My Php User Registration by netsage205: 7:13am On Feb 28, 2020
It is your database connection credentials, they are not correct, go and double check.
Re: I'm Having An Issue With My Php User Registration by resosdigital(m): 8:16am On Feb 28, 2020
Like others said your credentials are wrong. I see you specified port 3306 also ensure that mysql is indeed running on that port on your server.

Alternatively you can email your hosting provider and they should point out the right credentials for you to use
Re: I'm Having An Issue With My Php User Registration by ellagabs(f): 8:53am On Feb 28, 2020


i keep getting these errors

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'prakopwg_goodwill'@'localhost' (using password: YES) in C:\xampp\htdocs\Tor\server.php on line 15

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\Tor\server.php on line 21



first, i thought you said the errors you got were from a live server? but what am seeing here is you are running on a local sever.

secondly, if it's on yout local server, navigate to the Tor folder in your xamp's htdocs folder, open the file "server.php" with a text editor, copy the code and paste here.


alternatively, open your database under phpMyadmin, click on check privileges, confirm that the user password there is correct with what you have on your server.php file
Re: I'm Having An Issue With My Php User Registration by Nobody: 3:34pm On Feb 28, 2020
How do you people still cope with PHP without a framework..

Im assuming you don't intend on doing anything serious with the website because of serious security loopholes and integrity constraints violation.

I can't read what you have up there is like monkey code.
There are inbuilt methods to handle those things.

Go and learn a framework is more professional.
Try cakephp, laravel or codeigniter

(1) (Reply)

Blogging Certification Course In Lagos. #8,000 Only / I Want To Buy Unverified Adsense Plus Domain / Webmasters: Share Your Challenges

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2022 Oluwaseun Osewa. All rights reserved. See How To Advertise. 60
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.