Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. A solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate some of the SQL injection possibility currently open in your code. You could also place back ticks place back ticks (`) around your column and table names, but if your databases are made properly this shouldn't be necessary.
Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. A solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate some of the SQL injection possibility currently open in your code. You could also place back ticks (`) around your column and table names, but if your databases are made properly this shouldn't be necessary.
Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. A solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate some of the SQL injection possibility currently open in your code. You could also place back ticks (`) around your column and table names, but if your databases are made properly this shouldn't be necessary.
Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
MySQLi is acceptable, but not favorable. It's adequate, not excellent. I hate to be that guy who advertises one perfectly fine working method over another perfectly fine working method, but PDO really has it's benefits .
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. The easiest solution is a die
instead of the echo. The bestA solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job. If this code is actually in a function (which I doubt it is), then a die
again can work here in place of a return.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate some of the SQL injection possibility currently open in your code. And I wouldYou could also place back ticks (`) around your column and table names, but if your databases are made properly this shouldn't be necessary.
Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
MySQLi is acceptable, but not favorable. It's adequate, not excellent. I hate to be that guy who advertises one perfectly fine working method over another perfectly fine working method, but PDO really has it's benefits .
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. The easiest solution is a die
instead of the echo. The best solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job. If this code is actually in a function (which I doubt it is), then a die
again can work here in place of a return.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate the SQL injection possibility currently open in your code. And I would also place back ticks (`) around your column and table names.
Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. A solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate some of the SQL injection possibility currently open in your code. You could also place back ticks (`) around your column and table names, but if your databases are made properly this shouldn't be necessary.
Unfortunately, this snippet could be written a lot better, and it's already been written a lot better. However, I'll assume this isn't anything close to production and you're doing it for the learning process!
MySQLi is acceptable, but not favorable. It's adequate, not excellent. I hate to be that guy who advertises one perfectly fine working method over another perfectly fine working method, but PDO really has it's benefits.
Consider delving into the PDO world before getting to familiar with the MySQLi functions. Doing so will keep you on a good track to learning correct object oriented programming too.
Which bring us to the next point: your code is highly dependent and incredibly coupled and tight. I suggest you read up on some object oriented matters, like this, this, and this.
However, since your code isn't lookin' like that, I'll just jump to reviewing the code available.
Firstly, in your check to see if the connection is successful, your fail block only echo
s the error. That allows a broken connection to continue in the script; that's bad. The easiest solution is a die
instead of the echo. The best solution would be to throw an exception from a database connection class which would in turn allow the view to present a user friendly error.
Up next, you're using a real escape function. Prepare your statements instead.
Your empty string checking is a good example of guard clauses, good job. If this code is actually in a function (which I doubt it is), then a die
again can work here in place of a return.
Good for using the built-in email validation function!
When comparing password equality, it is acceptable to use <>
however it's easier to understand and read !==
. I'd suggest switching those.
And lastly, adding parameters to your queries would eliminate the SQL injection possibility currently open in your code. And I would also place back ticks (`) around your column and table names.